I am a .NET developer new to COM. I'd like to know what is the need of registering a COM component? What happens during registration.
In order for the OS to find a component when a program needs it, it must be registered with the system. The system then records it in the Registry.
Usually a component is registered by running the program REGSVR32.EXE, which assumes that the component has been properly coded to support the DLLRegisterServer() public method. Executing regsvr32.exe should respond with a dialog box indicating success or failure of the registration.
Read
COM uses the registry to map ProgIDs and CLSIDs to your component. This allows someone to Co-Create your COM component without needing to load your .dll manually, etc.
To instantiate a COM component the consumer calls CoCreateInstance() (either directly or it is called by some wrapper class - doesn't matter) providing it two GUIDs - class id and interface id. Then COM subsystem automagically finds what library or executable to load knowing just the class id provided. To do so it uses information in the registry that is written there during component registration.
Other infromation can be written as well. So-called ProgID can be used by the consumer to discover the class id given a symbolic name. It first calls CLSIDFromProgID() to translate the ProgID to a class id, then CoCreateInstance() again. The translation is done using the information in the registry.
COM objects can be created from any process on the system without knowing anything more that the name of the component eg. Word.Application . Since the creating application doesnt have to know where the dll or exe that contains the code resides something else must. The registry holds all this information
- The physical location of the file that implements the COM object.
- All the classes and Interfaces the COM object has.
- Other important information.
Without registration the calling application would need to know a lot more about where the dlls etc were, what methods they expose, how to call them etc. Infact you might as well be calling a good old fashioned DLL.
All registration is is a few entries in the registry but it makes lots of stuff simpler.