What is the need to register a COM component?

I am a .NET developer new to COM. I would like to know what is the need to register a COM component? What happens during registration.

+2


source to share


4 answers


In order for the OS to find a component when a program needs it, it must be registered with the system. The system then writes it to the Registry.

Typically, a component is registered by running the REGSVR32.EXE program, which assumes that the component has been properly encoded to support the DLLRegisterServer () public method. Executing regsvr32.exe should respond with a dialog box indicating registration success or failure.

Read



Understanding registering COM components

+2


source


To instantiate a COM component, a consumer calls CoCreateInstance () calls (either directly or called by some wrapper class - it doesn't matter), providing it with two GUIDs — the class ID and the interface ID. The COM subsystem then automatically finds which library or executable to load, knowing only the provided class identifier. To do this, it uses the information in the registry that is written there during the registration of the component.



Other information may also be written. The so called ProgID can be used by the consumer to locate a symbolic named class identifier. It first calls CLSIDFromProgID () to translate the ProgID to a class ID, and then CoCreateInstance () again. The translation is carried out using the information in the register.

+2


source


COM uses the registry to map ProgID and CLSID to your component. This allows someone to create their COM component without manually loading your .dll etc.

+1


source


COM objects can be created from any process in the system without knowing anything more than the name of the component, for example. Word.Application. As the creating application does not have to know where the dll or exe that contains the code is in a different location. The registry contains all this information.

  • The physical location of the file that implements the COM object.
  • All classes and interfaces of a COM object.
  • Other important information.

Without registration, the calling application needs to know a lot more about where the DLLs are located, etc., what methods they expose, how to call them, etc. Infact, you might as well refer to the good old DLL version.

All registration is a few registry entries, but this simplifies the upload process.

+1


source







All Articles