How to: Create a Basic ActiveX Object
You can create COM objects with the ActiveX Template Library provided with Microsoft® Visual C++.
You create Microsoft ActiveX controls specific to Visual FoxPro as you would any similar control. Most C++ compilers allow you to create skeletons of the control, and they can be created with the Microsoft Visual Basic Control Creation Edition.
The following sections describe the steps for creating an ActiveX control with Microsoft Visual C++ 6.0 for use in Visual FoxPro.
To create a project for the ActiveX control
Start Microsoft Visual C++.
From the File menu, choose New.
In the New dialog box, choose Project Workspace.
In the New Project Workspace dialog box, specify a project name.
In the Type list, choose OLE ControlWizard.
Choose Create, and then follow the steps in the wizard.
When the wizard is finished, you can build the ActiveX control immediately. However, you will also need to define properties and methods for the control.
To add properties and methods to the ActiveX control
From the View menu, choose ClassWizard.
Choose the OLEAutomation tab.
Choose Add Method or Add Property.
Fill in the name, parameter, and other information required by the element you are creating, and then choose OK.
Choose Edit Code to display the editor, and then enter the code that defines the property or method you are creating.
For example, to create a Version property that returns the .ocx file version as an integer (such as 101), you create the property with a return type of long, and add code similar to the following:
#define VERSION 101
long CPyCtrl::GetVersion()
{
// set the version number here
return VERSION;
}
Because the version number is ordinarily read-only, you wouldn't create a SetVersion( ) function.
See Also
Tasks
How to: Add Visual FoxPro API Calls
Concepts
Library or ActiveX Object Creation
Creating Visual FoxPro Dynamic-Link Libraries