Share via


Creating 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 follow sections describe the steps for creating an ActiveX control with Microsoft Visual C++ for use in Visual FoxPro.

To create a project for the ActiveX control

  1. Start Microsoft Visual C++.
  2. From the File menu, choose New.
  3. In the New dialog box, choose Project Workspace.
  4. In the New ProjectWorkspace dialog box, specify a project name.
  5. In the Type list, choose OLE ControlWizard.
  6. Choose Create, and then follow the steps in the wizard.

When the wizard is finished, you can build the ActiveX control immediately. However, you'll also need to define properties and methods for the control.

To add properties and methods to the ActiveX control

  1. From the View menu, choose ClassWizard.
  2. Choose the OLEAutomation tab.
  3. Choose Add Method or Add Property.
  4. Fill in the name, parameter, and other information required by the element you are creating, and then choose OK.
  5. Choose Edit Code to display the editor, and then enter the code that defines the property or method you're 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

Library or ActiveX Object Creation | Creating a Basic FLL Library | Accessing the Visual FoxPro API | Extending Visual FoxPro with External Libraries | Adding Visual FoxPro API Calls