Export (0) Print
Expand All

Registering Classes [Automation]

Objects that can be created with CoCreateInstance must also be registered with the system. For these objects, registration maps a CLSID to the Automation component file (.dll or .exe) in which the object resides. The CLSID also maps an ActiveX object back to its application and ProgID.

The following figure shows how registration connects ProgIDs, CLSIDs, and ActiveX components.

ProgID

The type library can be obtained from its CLSID using the following syntax:

\CLSID\TypeLib = {UUID of type library}

The following syntax indicates that the server is an ActiveX component:

\CLSID\Programmable 

The following shows the resulting example code; these COM class registry keys are required:

HKEY_CLASSES_ROOT\CLSID\{F37C8061-4AD5-101B-B826-00DD01103DE1} = Hello 2.0 Application
HKEY_CLASSES_ROOT\CLSID\{F37C8061-4AD5-101B-B826-00DD01103DE1}\ProgID = Hello.Application.2
HKEY_CLASSES_ROOT\CLSID\{F37C8061-4AD5-101B-B826-00DD01103DE1}\VersionIndependentProgID = Hello.Application
HKEY_CLASSES_ROOT\CLSID\{F37C8061-4AD5-101B-B826-00DD01103DE1}\LocalServer32 = hello.exe /Automation
HKEY_CLASSES_ROOT\CLSID\{F37C8061-4AD5-101B-B826-00DD01103DE1}\TypeLib = {F37C8060-4AD5-101B-B826-00DD01103DE1}
HKEY_CLASSES_ROOT\CLSID\{F37C8061-4AD5-101B-B826-00DD01103DE1}\Programmable

The registration file uses the following syntax for each class of each object that the application exposes.

\CLSID\{UUID} = human_readable_string
\CLSID\{UUID}\ProgID = AppName.ObjectName.VersionNumber
\CLSID\{UUID}\VersionIndependentProgID = AppName.ObjectName
\CLSID\{UUID}\LocalServer[32] = filepath[/Automation]
\CLSID\{UUID}\InProcServer[32] = filepath[/Automation]

human_readable_string

A string that describes the object to users. The recommended maximum length is 40 characters.

AppName

The name of the application, as specified previously in the application registration string.

ObjectName

The name of the object to be registered.

VersionNumber

The version number of the object.

UUID

The universally unique identifier for the application CLSID. To generate a UUID for your class, run the utility Guidgen.exe.

filepath

The full path and name of the file that contains the object. The optional /Automation switch tells the application it was launched for Automation purposes. The switch should be specified for the Application object's class. For more information on /Automation see Initializing the Active Object.

The ProgID and VersionIndependentProgID are used by other programmers to gain access to the objects you expose. These identifiers (IDs) should use consistent naming guidelines across all your applications as follows:

  • Can contain up to 39 characters.

  • Must not contain any punctuation (except for the period).

  • Must not start with a digit.

Version-independent names consist of an AppName.ObjectName, without a version number. For example, Word.Document or Excel.Chart.

Version-dependent names consist of an AppName.ObjectName.VersionNumber, such as Excel.Application.5.

LocalServer[ 32]

Indicates that the ActiveX component is an .exe file and runs in a separate process from the ActiveX client. The optional 32 specifies a server intended for use on 32-bit Windows systems.

InProcServer[ 32]

Indicates that the ActiveX component is a DLL and runs in the same process space as the ActiveX client. The optional 32 specifies a server intended for use on 32-bit Windows systems.

The filepath you register should give the full path and name. Applications should not rely on the MS-DOS PATH variable to find the object.

Show:
© 2014 Microsoft