Basic COM   «Prev  Next»
Lesson 6In-process COM servers: Registering and unregistering COM objects
ObjectiveDescribe how an in-process server registers COM objects.

In-process COM Servers: Registering and unregistering COM Objects

In-process COM servers provide the following required registry entries for each COM object they implement.
HKCR\CLSID\ {clsid} Under HKEY_CLASSES_ROOT\CLSID the COM object's CLSID, delimited by curly brackets ({}), is added as a key. For example:
HKEY_CLASSES_ROOT\CLSID\ {5E533531-5EAC-11d2-85D9-08001700C57F}
Each COM object in a server is registered using a different CLSID. COM uses the CLSID registry entry to find the server that implements a specific COM object.
HKCR\CLSID\{clsid} value The value portion of the CLSID entry is optional. Normally, applications put the name of the COM object in as the value. For example:
HKEY_CLASSES_ROOT\CLSID\ {5E533531-5EAC-11d2-85D9-08001700C57F} = "MyComObject"
HKCR\{clsid} \InprocServer32 Under HKEY_CLASSES_ROOT\CLSID\{ ... }, a subkey called InprocServer32 is added. For example:
HKEY_CLASSES_ROOT\CLSID\ {5E533531-5EAC-11d2-85D9-08001700C57F}\ InprocServer32
HKCR\CLSID\{clsid} \InprocServer32 value The value associated with the InprocServer32 key is the full directory path to the DLL housing the in-process server. For example:
HKEY_CLASSES_ROOT\CLSID\ {5E533531-5EAC-11d2-85D9-08001700C57F}\ InprocServer32 = "c:\Dev\MyComObject\Debug\ComServer.dll"
ProgID Other optional entries include a ProgID. A ProgID is a string that can be used to look up an object's CLSID.
Exported functions In-process servers implement two exported functions to support registering and unregistering COM classes, DllRegisterServer and DllUnregisterServer.
When DllRegisterServer is called, a server should register each COM object it implements. When DllUnregisterServer is called, a server should remove all entries for its COM objects from the registry.
Registration with RegSvr32 Command-line tool RegSvr32.exe is used to register and unregister in-process servers.
Regedit.exe can be used to examine the contents of the registry.

In-process COM servers: Registering and unregistering COM objects

RegEdit is a registry browser and management tool. NT also had a tool known as RegEdt32. The following diagram shows a COM object's entries.

Regedit or Registry Editor


Jeder Prozess, der ein COM-Objekt enthält, erhält dynamisch eine Portnummer zwischen 1024 und 65535. Das nachfolgende REGEDIT4-Listing zeigt die notwendigen Registry-Einträge, um die Ports einzuschränken. Im folgenden Beispiel werden nur die Ports 4000-6000 erlaubt.

Listing 3-6. Registry-Einstellungen zur Einschränkung der DCOM-Ports

dllCanUnloadNow - Exercise

Click the Exercise link below to apply what you have learned about COM server registry settings.
dllCanUnloadNow - Exercise