Need to make my own COM server with C#  
Author Message
Sioln





PostPosted: Visual C# Language, Need to make my own COM server with C# Top

Hi.

I've tried to search, but search results on word COM at microsoft.com are amazing.

Tell me please, where can I find any tutorial or example to build COM server in C# (.NET 2.0)

I've found this

http://www.hide-link.com/ ~gopalan/dotnet/classic_com/com.net_quoteserver.html

but it not helps to me.



Visual C#14  
 
 
TaylorMichaelL





PostPosted: Visual C# Language, Need to make my own COM server with C# Top

A COM server is simply a COM class that provides services to another component (the COM client). You create a C# COM class by creating a normal class and attributing it with at least ComVisible. You should also use Guid to specify a unique identifier. Furthermore you should create a COM-visible interface to expose to COM. The class must implement this interface and the interface can not expose non-COM visible managed classes (value types are okay). The interface must also be attributed. Finally you should use the ClassInterface attribute on your COM class to avoid the compiler creating a COM visible interface for you.

[ComVisible(true)]
[Guid(...)]
public interface IMyComInterface
{
...
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Guid(...)]
public class MyComClass : IMyComInterface
{
...
}

If you want your COM code to be visible to VB you need to add DispId attributes to each of your members of your interface. Finally be sure to check the option in the project settings to register the assembly for COM interop so it will auto-register (for debugging purposes only).

Now sometimes people say COM server but they really mean an out-of-process COM server. In this case the steps are the same exception you'll generate a console application instead of a DLL. In this case your process will be started the first time someone tries to create an instance of your class.

For more information search on the attributes given above and also on the topic of COM server and C# to get useful links.

Michael Taylor - 12/6/06