COM Servers

  • Thread starter Thread starter glenn
  • Start date Start date
G

glenn

How do you write a COM server in C# VS 2003? I can't believe it but I can't
even find the words COM in the help for VS related to COM servers. Did
Microsoft Rename it again or can VS C# not handle the task? Why is there
nothing available for me to read?

Thanks,

glenn
 
How do you write a COM server in C# VS 2003? I can't believe it but I can't
even find the words COM in the help for VS related to COM servers. Did
Microsoft Rename it again or can VS C# not handle the task? Why is there
nothing available for me to read?
Because C# is a .NET langauge, there isn't direct support for building
COM servers, you should be thinking .NET assemblies. If you aren't
going to stick to .NET, VS C++ still includes the ATL framework, which
is probably the most comprehensive way to put together COM servers.
 
So to get this straight. If I want to write a COM server that would allow
someone writing another program in another language, I can not use C#? Boy
does this change my opinion of .NET rather dramatically....

Thanks,

glenn
 
Jason said:
Because C# is a .NET langauge, there isn't direct support for building COM
servers, you should be thinking .NET assemblies. If you aren't going to
stick to .NET, VS C++ still includes the ATL framework, which is probably
the most comprehensive way to put together COM servers.

C# is a programming language, and as such doesn't support COM directly (nor
does C++), but this is handled by the Framework and the CLR. That means that
basically each managed class can be exposed as a COM class, sure you have to
respect some design guidelines when exposing to native COM clients, but it's
perfectly possible and fully supported and used extensively by the framework
and VS.

To OP, check the MSDN library -
http://msdn.microsoft.com/library/d...l/cpconcominteropsamplenetclientcomserver.asp

and this:
http://msdn.microsoft.com/library/d...l/cpconcominteropsamplenetclientcomserver.asp
and this:

http://msdn.microsoft.com/library/d...l/cpconcominteropsamplenetclientcomserver.asp

COM servers can be implemented by deriving from ServicedComponent and can be
exposed to COM clients and .NET clients.
Check:
http://msdn.microsoft.com/library/d...de/html/cpconwritingservicedcomponents.aspfor details:Willy.
 
glenn said:
So to get this straight. If I want to write a COM server that would allow
someone writing another program in another language, I can not use C#?
Boy
does this change my opinion of .NET rather dramatically....

Thanks,

glenn

Sure you can, .NET makes it easier than before to write COM components, see
my other reply.
And if you are looking for some real good readings consider these (in order
of my personal preferences):

http://www.amazon.com/exec/obidos/ASIN/067232170X/102-7344360-6822569

http://www.amazon.com/exec/obidos/t...2/102-7344360-6822569?_encoding=UTF8&v=glance

http://www.amazon.com/exec/obidos/t...4/102-7344360-6822569?_encoding=UTF8&v=glance

Willy.
 
Yes it's true there is no direct support for building COM components, but
there is a rich interop layer in .NET which allows communication in both
directions between .NET and COM components (albeit with a few limitations
and perhaps performance overhead compared with pure COM).
Some links here covering basic principles:
http://msdn.microsoft.com/vstudio/using/understand/interop/default.aspx

There is also COM+/EnterpriseServices, which provides another attractive
alternative for integrating with COM (especially looking forward to
"Longhorn/Indigo").
Take a look at System.EnterpriseServices namespace in the .NET framework.

As for terminology - roughly speaking COM+MTS became COM+ which became
component-services/enterprise-services in today's terminology.
 
How much of a performance hit? I am use to writing my COM servers in
Borland Delphi. Are my components written in C# going to be drastically
slower?

Thanks,

glenn
 
How much of a performance hit? I am use to writing my COM servers in
Borland Delphi. Are my components written in C# going to be drastically
slower?

Here are my thoughts:
1 - You could continue using Delphi to write your COMs
2 - C# + COM => Interop call. This can be very expensive if there are
many many calls!
 
Problem is I would eventually like to get to a single programming language
for this project. I don't want to have to continue to program in 2
languages and as it stands its starting to look like Delphi might be the
best choice. It seems to generate much faster code, has a much better IDE
with lots more components, manages code a lot better, and the data access
elements of the language are far better designed and thought out than it
appears have been done in VS2003. One reason I'm holding off is I want to
see if any of these items have been addressed in VS2005 but I have no idea
how long that wait is going to be.

And it also sounds like the COM elements of it are going to be the same
which means any interfaces I write that I need to share with other companies
are going to run much slower than if written in Delphi.

This is very disappointing...

glenn
 
Are your clients specifying COM? If they are using .NET languages, you
can use .NET assemblies (no interop hit), and if they are using an old
version of VB or C++, they can use interop (VB6 users have no right to
complain about performance, anyway!). Current versions of Delphi,
AFAIK, are capable of using .NET assemblies native.

Last I messed with Delphi was version 5. COM support was a bit weak
back then, maybe it's gotten better since then (setting up things like
collection classes for supporting for/each contstructs was painful,
stuff like that).

I would imagine that future versions of VS will concentrate more on
expanding .NET support, as opposed to COM.



Problem is I would eventually like to get to a single programming language
for this project. I don't want to have to continue to program in 2
languages and as it stands its starting to look like Delphi might be the
best choice. It seems to generate much faster code, has a much better IDE
with lots more components, manages code a lot better, and the data access
elements of the language are far better designed and thought out than it
appears have been done in VS2003. One reason I'm holding off is I want to
see if any of these items have been addressed in VS2005 but I have no idea
how long that wait is going to be.

And it also sounds like the COM elements of it are going to be the same
which means any interfaces I write that I need to share with other companies
are going to run much slower than if written in Delphi.

This is very disappointing...

glenn
 
Willy,

I purchased the first book you recommended in Digital form and I have to
say, while he does go through quite a bit of explanation I have yet to find
a single example in the book that actually works. And the things that he
seems to get wrong, he offers no explanations on. I downloaded the source
code for the book from SAM's website and its most in VB and the examples
given in the book are not even in the download. Only the major examples.

So while I am learning, I would not recommend this particular book to
anyone. It is very frustrating to be trying to figure this stuff out, pay
almost $50 bucks for a book and have it do nothing but frustrate you even
more due to the lack of attention to detail...

Do you know if any of the other books you have listed have working examples
or are they pretty much the same as this book?

Thanks,

glenn
 
glenn said:
Willy,

I purchased the first book you recommended in Digital form and I have to
say, while he does go through quite a bit of explanation I have yet to
find
a single example in the book that actually works. And the things that he
seems to get wrong, he offers no explanations on. I downloaded the source
code for the book from SAM's website and its most in VB and the examples
given in the book are not even in the download. Only the major examples.

So while I am learning, I would not recommend this particular book to
anyone. It is very frustrating to be trying to figure this stuff out, pay
almost $50 bucks for a book and have it do nothing but frustrate you even
more due to the lack of attention to detail...

Do you know if any of the other books you have listed have working
examples
or are they pretty much the same as this book?

Thanks,

glenn

I suppose you are talking about Adam Nathan's .NET and COM: The Complete
Interoperability Guide, right?
I didn't know that the code samples were available for download, after all
this is a text book not a work book.
I have the in-print edition, I don't say it's perfect, but I've only met a
few inaccuracies, which IMO is quite normal when you consider it covers, in
1600 pages, everything you possibly should know about the subject and that
it was written based on a Beta version v1.0 .
Do you mind to share were he got wrong (just the page numbers of a few
samples)?

Another good reading is COM and .NET Interoperability by Andrew Troelsen
http://www.apress.com/book/supplementDownload.html?bID=81&sID=371

Willy.
 
Well, possibly he didn't get it wrong and its based on the fact that things
have changed, however, you can pretty much choose any sample code up to
chapter 8 and it won't compile as is printed. The very first example uses
the speech engine from microsoft but the parameters he's passing in are
invalid and won't compile so I had to just use another COM server for the
example.

I'm currently trying to compile and use the COM Server section listed as the
first example of chapter 8. He has me generating strong names that I've
never done before but the code he has me adding to the application for the
Strong name won't compile and says its a duplicate name or something.

But as I stated, perhaps the problem is more that he wrote the book long
before 2003 was out and things have changed substantially causing small
problems with each example. But for a frustrated programmer trying to learn
this stuff its only serving to frustrate me more...

Thanks,

glenn
 
Back
Top