Home | Overview | How Do I | FAQ | Tutorial | Sample
SVBX control migration was available only through the VBX template tool, a part of the ControlWizard found in version 1.x of the CDK. Because this tool was removed from the ControlWizard shipped with Visual C++ 4.0, migrating existing VBX controls requires version 1.x of the CDK. The only option for VBX migration using VC ++ 4.0 is to create a framework from ControlWizard and manually port the entire code base of the VBX control into the ActiveX control framework.
As stated above, developers with existing VBX controls can use the VBX template tool, found in the CDK ControlWizard, to convert existing VBX controls to the ActiveX control format.
The VBX template tool helps you migrate your VBX custom control to an ActiveX control. The template tool uses model information in the .VBX file and creates a Visual C++ project file, as well as source code files for creating the ActiveX control. These files can be compiled and linked to produce a working framework for the ActiveX control.
Once this framework is built and tested, the next step is to take code from your VBX source files and place it in the appropriate areas of the generated OLE source files. The transplanted code will probably require some degree of modification to work in the new source code files.
This article explains:
If you want to port your ActiveX control framework to Visual C++ 4.0, see the article ActiveX Controls: Converting a CDK Project to a Visual C++ Project.
For the VBX template tool to properly translate the VBX control, you must expose the VBX control model information to the template builder, using the VBGetModelInfo function. If your VBX source code does not already define this function, first define a MODELINFO structure containing a specific Visual Basic version number, and a NULL-terminated array of MODEL structures. The MFC ActiveX controls sample CIRC3, listed under CONTROLS, defines the MODELINFO structure as follows:
LPMODEL modellistCircle[] =
{
&modelCircle,
NULL
};
Note Remember to NULL-terminate the array of model pointers.
MODELINFO modelinfoCircle =
{
VB_VERSION, // VB version being used
modellistCircle // MODEL list
};
Note If your .VBX file provides different models to support earlier versions, you should create similar MODELINFO structures to point to those models. The CIRC3 custom control, for example, also defines ModelinfoCircle_VB1
and ModelinfoCircle_VB2
structures.
Once you have defined the MODELINFO structure(s), you can define the VBGetModelInfo function, as an export, in your source code. The MFC ActiveX controls sample CIRC3, listed under CONTROLS, defines the function:
LPMODELINFO FAR PASCAL _export VBGetModelInfo
(
USHORT usVersion
)
{
if (usVersion <= VB100_VERSION)
return &modelinfoCircle_Vb1;
if (usVersion <= VB200_VERSION)
return &modelinfoCircle_Vb2;
else
return &modelinfoCircle;
}
Once this function is defined, rebuild your VBX control before using the template tool.
After your VBX control has been built with the VBGetModelInfo function, as described in the previous topic, you are ready to run the VBX template tool.
As mentioned before, you must be using the ControlWizard that shipped with version 1.x of the CDK. The template tool is not available with Visual C++ 4.0.
If you only need to use the ControlWizard shipped with version 1.x of the CDK, you can copy two files from the distribution CD. These two files, CTLWZLIB.DLL and MFCCTLWZ.EXE, is in the vc152\msvccdk directory of the Visual C++ Version 1.52 CD.
To run the VBX template tool
Note If you select a .VBX file that does not properly export the model information (as described in the Note in Preparing the VBX Custom Control), Visual C++ may crash at this point.
In addition, a subdirectory for the Type library file is created. If you are using the 16-bit version of the CDK, it is called TLB16. If you are using the 32-bit version of the CDK, it is called OBJDU.
The README.TXT file contains a summary description of each file created by the VBX template tool. These files are all that is required to build a complete working framework of the new ActiveX control.
The template generated by the VBX template tool is similar to the "blank" template that is generated when you use ControlWizard to create a new control, with the following differences:
ControlWizard converts most of the standard properties and events in your .VBX to fully implemented stock properties and events in the template's source code.
Stock properties supported by the VBX template tool include:
Stock events supported by the VBX template tool include:
Note A number of properties not mentioned above that were formerly standard in the .VBX Control model are automatically supported by ActiveX as standard "extender" properties (e.g., Left, Top, Height, Width). Therefore, these properties are not needed in an ActiveX control, and are not converted by the VBX template tool.
Stock properties of the VBX model not supported:
Stock events of the VBX model not supported:
Custom properties and events in your VBX control are provided in the template as stub functions. In order to make these properties and events functional, you must port the implementation code from your VBX control’s source files into the appropriate files in the new control template. These places are indicated by similar comments in the template's source code files:
// TODO: Initialize your control's instance data here.
After ControlWizard generates the basic framework for your VBX control, build and test the control to familiarize yourself with ActiveX control behavior. The following sections describe this process and demonstrate how to use Test Container to test your new ActiveX control.
Note that the following information only applies if you are using the 16-bit version of Visual C++. If you are using the 32-bit version of Visual C++, the type library is automatically generated by the control makefile.
Before you can compile and link the control template, you must create a type library, used by control containers that use your control. This will be based on the information contained in the Object Description Library (.ODL) file created by the porting tool.
To create the type library
Note that the following information only applies if you are using the 16-bit version of Visual C++.
After creating the Type Library, you can build the framework control by choosing Build from the Visual C++ Project menu.
When the project has built successfully, you must register the new control before you can test it. Choose Register Control from the Tools menu. A message box appears, indicating that the control was successfully registered.
For procedures on testing your ActiveX control framework, see the article Test Container.
When you are satisfied that the control framework is working properly, the next step is to port the implementation of your ActiveX control's custom properties and events from your VBX source code to the new control's source code files. To do this, use ClassWizard and the implementation guidelines in the ActiveX controls articles. Remember to back up your files frequently and to use Test Container to test each new block of code as you go.
Once the VBX control is ported to a CDK project, you could port the CDK project to Visual C++ 4.0 by following the steps given in the article ActiveX Controls: Converting a CDK Project to a Visual C++ Project.