Creating COM server with C#

  • Thread starter Thread starter m.a
  • Start date Start date
M

m.a

Hello,

Where can I find detail information about how I can create a COM server
with C#? Is there any tutorial or any book in this subject?



I am using MSVC 2005 professional or MSVC 2008 express.



Thanks
 
You cannot AFAIK write a native COM server in C#.

What you *can* do is write a "serviced component" (i.e. a COM+ dll that
you can host as a COM+ application in "Component Services".

http://msdn.microsoft.com/en-us/library/ty17dz7h.aspx

Alternatively, you can use a COM-server compatible framework to write a
shim COM server to the managed (.NET) COM library (dll); for
quick'n'dirty jobs I've used VB6 for this; or C++ if you are literate
with it (I'm not very...).

Marc
 
Marc Gravell said:
You cannot AFAIK write a native COM server in C#.

What you *can* do is write a "serviced component" (i.e. a COM+ dll that
you can host as a COM+ application in "Component Services".

http://msdn.microsoft.com/en-us/library/ty17dz7h.aspx

Alternatively, you can use a COM-server compatible framework to write a
shim COM server to the managed (.NET) COM library (dll); for quick'n'dirty
jobs I've used VB6 for this; or C++ if you are literate with it (I'm not
very...).

Marc


Thanks Marc,
What is the difference between COM and COM+? I want to use my COM in
matlab. Can I write COM+?

Regards
 
In many simple cases, not a huge amount - you're simply piggy-backing
off COM+'s ability to host a library in a host exe as a service. But
COM+ has support for a lot of things like transaction support (think:
DTC / TransactionScope). You don't have to use them, though.

As for matlab, no idea; but the point is that COM+ acts as the COM
server. So it might be wroth a try with a quick test project (just don't
write everything until you know the concept is sound).

Marc
 
m.a said:
Thanks Marc,
What is the difference between COM and COM+? I want to use my COM in
matlab. Can I write COM+?

Regards
It is pretty easy to expose interfaces as COM. You just need to decorate
the interface and or its methods with [ComVisible(true)] following is an
example interface.
[ComVisible(true)]
public interface ITypeDefinition : IDisposable
{
/// <summary>
/// Get the name of this type
/// </summary>
String TypeName{get;}
}

Once you have the assembly built you can use the regasm tool to register it.

Use help on ComVisible and regasm to find out the details. You might
check www.codeproject.com for examples. I find most everything I have
questions about has some sort of example there.

Hope that helps.
Leon Lambert
 
Yes, exposing as COM is tricky - but exposing as a COM *server* (exe) as
opposed to a COM *library* (dll) is the tricky bit.

Of course, it is entirely possible that the OP hasn't used "server" as a
technical term, but simply means "COM", in which case a library should
work fine.

Marc
 
Of course - maybe I am using the term incorrectly ;-p

I'll use different terms...

If you just need a callable COM object, then yes, it is easy. If you
need it to be out-of-process, then it is harder.

Marc
 
Back
Top