Microsoft KB Archive/119672

= CDK: Writing VBXs in C++ or Large Memory Model =

Article ID: 119672

Article Last Modified on 10/29/2003

-

APPLIES TO


 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q119672



SUMMARY
The Visual Basic custom control (VBX) architecture assumes that a controls model structure and related data structures will be in the default data segment for the VBX. This means that controls developed with the control development kit (CDK) for Visual Basic should be compiled either through the medium-memory model or with an explicit NEAR declaration on the appropriate data structures. Failure to declare variables with an explicit NEAR declaration will result in the following error:

Cannot Load VBX



MORE INFORMATION
Visual Basic expects that the model structure will reside in the default data segment for the VBX and that all pointers in the model structure will be near pointers. When you use the medium-memory model to compile, pointers are near by default. If you need to compile using another memory model that does not assume near pointers, then you need to force the compiler to generate near addresses for your property list, event list, and model structure. You can do this by putting the NEAR keyword in the corresponding declarations. Below is a code fragment taken from the Circ1 sample: PPROPINFO Circle_Properties[] = {      PPROPINFO_STD_CTLNAME, ...

PEVENTINFO Circle_Events[] = {      PEVENTINFO_STD_CLICK, ...

MODEL modelCircle = {      VB_VERSION,         // VB version being used ... Because there are no specific NEAR/FAR declarations in the above examples, the compiler will use the default for the given memory model. You can, however, force these pointers to be NEAR by specifying NEAR in the declaration: PPROPINFO NEAR Circle_Properties[] = {      PPROPINFO_STD_CTLNAME, ...

PEVENTINFO NEAR Circle_Events[] = {      PEVENTINFO_STD_CLICK, ...

char NEAR szCircle[] = "Circle";  // Must be NEAR char NEAR szCirc1[] = "CIRC1";    // Must be NEAR

MODEL NEAR modelCircle =          // Must be NEAR {      VB_VERSION,                    // VB version being used 0,                            // MODEL flags (PCTLPROC)CircleCtlProc,      // Control procedure CS_VREDRAW | CS_HREDRAW,      // Class style WS_BORDER,                    // Default Windows style 0,                            // Size of CIRCLE structure IDBMP_CIRCLE,                 // Palette bitmap ID       szCircle,                      // Default control name szCirc1,                      // Visual Basic class name NULL,                         // Parent class name Circle_Properties,            // Property information table Circle_Events,                // Event information table IPROP_CIRCLE_HEIGHT,          // Default property IEVENT_CIRCLE_CLICK,          // Default event -1                            // Property representing value of ctl }; Now, even if you compile with another memory model that does not default to near pointers, near pointers will be generated for these constructs.

Additionally, if you have custom properties or custom events, you will need to declare them as "near" also. Below is an example custom property taken from Circ3: PROPINFO Property_CircleShape = {      "CircleShape", ... However, it too must be modified as follows: char NEAR szCircleProperty[] = "CircleShape";

PROPINFO NEAR Property_CircleShape = {      szCircleProperty, ...

Additional query words: 3.00

Keywords: KB119672

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.