Saturday, December 6, 2008

Registering server

The COM subsystem uses the Windows registry to locate and start all COM objects. Each COM server is responsible for self-registering, or

writing its entries into the registry. Thankfully, this task has been mostly automated by ATL, MIDL and the ALT wizard.

One of the files created by MIDL is a registry script. This script contains all the definitions required for the successful operation of our server.

Here is the generated script:

HKCR

{

BeepObj.BeepObj.1 = s 'BeepObj Class'

{

CLSID = s '{861BFE30-56B9-11D1-BD65-204C4F4F5020}'

}

BeepObj.BeepObj = s 'BeepObj Class'

{

CurVer = s 'BeepObj.BeepObj.1'

}

NoRemove CLSID

{

ForceRemove

{861BFE30-56B9-11D1-BD65-204C4F4F5020} =

s 'BeepObj Class'

{

ProgID = s 'BeepObj.BeepObj.1'

VersionIndependentProgID = s 'BeepObj.BeepObj'

ForceRemove 'Programmable'

InprocServer32 = s '%MODULE%'

{

val ThreadingModel = s 'Apartment'

}

}

}

}

Registry Scripts

You may be familiar with .REG scripts for the registry. RGS scripts are similar, but use a complete different syntax and are only used by ATL for

object registration. The syntax allows for simple variable substitution, as in the %MODULE% variable. These scripts are invoked by the ATL

Registry Component (Registrar). This was defined with a macro in the object header:

DECLARE_REGISTRY_RESOURCEID(IDR_BEEPOBJ)

Basically, this script is used to load registry settings when the server calls CComModule::RegisterServer(), and to remove them when

CComModule::UnregisterServer() is called. All COM registry keys are located in HKEY_CLASSES_ROOT. Here are the registry keys being set:

l BeepObj.BeepObj.1 - Current version of the class.

l BeepObj.BeepObj - Identifies the COM object by name.

l CLSID - The unique class identifier for the Object.

There are several sub-keys under the CLISD:

l ProgID - The programmatic identifier.

l VersionIndependentProgID - Associates a ProgID with a CLSID.

l InprocServer32 - Defines a server type (as a DLL). This will vary depending on whether this is an In-Process, Local, or Remote server.

l ThreadingModel - The COM threading model of the object.

l TypeLib - The GUID of the server's type library.

Developed Under:

0 comments: