How to: Expose ActiveX Objects

To expose ActiveX objects, you write code to initialize the objects, implement the objects, and then release OLE when the application terminates.

To initialize exposed objects

  1. Initialize OLE.

  2. Register the class factories of the exposed objects.

  3. Register the active object.

To implement exposed objects

  1. Implement the IUnknown, IDispatch, and virtual function table (VTBL) interfaces for the objects.

  2. Implement the properties and methods of the objects.

To release OLE when the application terminates

  1. Revoke the registration of the class factories and revoke the active object.

  2. Uninitialize OLE.

To retrieve active objects for use by others

  1. Use the Object Description Language (ODL) to create an .odl file, or use the Interface Definition Language (IDL) to create a library section in an .idl file that describes the properties and methods of the exposed objects. Use the Microsoft Interface Definition Language (MIDL) compiler to compile both the .idl file and .odl file.

  2. Create a registration (.reg) file for the application.

In this section

Topic Description
Initializing Exposed Objects
To initialize OLE and exposed objects, use OleInitialize, CoRegisterClassObject, and RegisterActiveObject.
Implementing Exposed Objects
To expose ActiveX objects, you must implement certain interfaces.
Implementing a Class Factory
This topics describes what you must do to expose objects for Automation.
Exposing the Application Object
The Application object identifies the application and provides a way for ActiveX clients to bind to and navigate the application's exposed objects. All other exposed objects are subordinate to the Application object; it is the root-level object in the object hierarchy.
Creating a Registration File
Before an application can use OLE and Automation, the OLE objects must be registered with the user's system registration database.
Releasing OLE and Objects
To release OLE and the exposed objects, use the RevokeActiveObject, CoRevokeClassObject, and OLEUninitialize functions.
Retrieving Objects
Automation provides several functions to identify and retrieve the active instance of an object or application, so you can make the object available to others.
Returning Objects
To return an object from a property or method, the application should return a pointer to the object's implementation of the IDispatch interface.
Shutting Down Objects
Describes how to shut down an ActiveX object.