C# .NET - COM - Asked By Naresh Kumar on 05-Jan-10 01:58 AM

Can any one please explain me about COM with simple terms.

Thanks in advance.

Re - Huggy Bear replied to Naresh Kumar on 05-Jan-10 02:26 AM

Abbreviation of COM Component Object Model, it was introduced by microsoft initially to pave a way for inter process communications. In order to make use of a COM component in an application first it has to be registered to the registry, which will also create a class id for it in the registry.
When you try using a COM component in your application it will create a COM callable wrapper which  is often termed as the COM interop.

After COM microsoft came up with COM+, the major problem which was raised by the COM usage was "The Dll Hell", which was not allowing multiple versions of the same COM component to be registered until the older version is deleted. The .NET framework was introduced by Microsoft which made use of the GAC instaed of registry there by extending the support for multiple versions of a library.

In order to register a COM component in your machine, you can make use of the Regsvr32 command. Below is the syntax of it.

regsvr32 -i <dll name with path>

to unregister

regsvr32 -u <dll name with path>

COM - Naresh Kumar replied to Huggy Bear on 05-Jan-10 02:38 AM

Thanks for the reply, I have some doubts please clarify.

I have created a new class library and added a number of classes, When I build this it will generate a DLL.
I can say this is a component now?, I use this in a website by adding DLL generated to bin folder or I can add this
to GAC.

You have mentioned "inter process communications" Can you explain this term.

Please reply thanks in advance.

Re - Huggy Bear replied to Naresh Kumar on 05-Jan-10 02:54 AM

If you have created a library in .NET, it is no more a COM component, it is called as a .NET assembly. So you can't say it as a COM component. When you generate a .NET library then you can either push it to GAC and use it from there or you can refer it from the bin folder only.

If you are planning to install multiple versions of the library on the server then better opt for pushing the library to GAC. To do this you got to generate a strong name key for your assembly using the below coomand.

sn -k "yourpathwithfilename.snk"

Use GACUTIL.exe to push it to the GAC once the assembly is properly signed. Below is the syntax.
gacutil -I "yourpathwithdllname.dll"

"inter process communications" - Making use of the same component across multiple applications.
COM - Naresh Kumar replied to Huggy Bear on 05-Jan-10 03:02 AM
You are saying, if I have created a library in .NET, it is no more a COM component, it is called as a .NET assembly.
Then what is a COM component, how we can create these and how we can use this in .NET applications.

I am a beginner to this please help me.

Thanks in advance.





RE - COM - DL M replied to Naresh Kumar on 05-Jan-10 03:06 AM
Re - Huggy Bear replied to Naresh Kumar on 05-Jan-10 04:01 AM
For example classic VB 6.0 components are of COM nature.
In order to make use of them you need to simply register them using the regsrv32.exe on your development box. Below is the syntax.

Regsvr32 -i COMComponentwithpath.dll

Once registered successfully you can directly refer it in your projects. 
If you refer to your project the IDE will create a COM CALLABLE WRAPPER for it called as COM interop.
Your .net code will use the interop as a wrapper class for COM access and it will take care of the communication between the .net assembly and the COM component.