Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

COM References problem in C# VS2008

0 views
Skip to first unread message

Milan

unread,
Nov 20, 2009, 3:01:01 PM11/20/09
to
Hi Volks,


I just try using/generating COM under C# .NET VS2008 and I have 3 questions:

1. why in some projects I see GUID defined for every interface and class and
in some projects is only written [ComVisible(true)] ? Why both approaches are
allowed ?

2. I did register COM "MyClassLibrary.dll" with:

regasm MyClassLibrary.dll /tlb: MyClassLibrary.TLB

and in another project(but in the same solution) I needed reference to
MyClassLibrary.dll COM object but in COM Tab von "Add Reference" Dialog there
was only MyClassLibrary.TLB and not MyClassLibrary.dll !?
In order to use COM I needed to go to location where COM MyClassLibrary.dll
is located and to add it as assembly reference. In the normal COM programming
one expect to use COM and OS should find (through Registry entry) exact COM
location, right ?
Why In COM Tab where the list of all COM are is not listed
MyClassLibrary.dll ?

3. in a couple of examples projects I saw in Object Browser (after double
click on COM reference) that name of COM in "Object Browser" tool is not any
more "Some_COM_Name" but "Interop.Some_COM_name", why ?


Any help is appretiated!

BR,
Milan

Wilson, Phil

unread,
Nov 20, 2009, 4:48:28 PM11/20/09
to
COM is interface-based, so good practice is to declare interfaces and
methods with interface ids and class guids. In C++ you had no choice but to
do this. In C# you can decide not to, and use ComVisible, and get a load of
stuff (like an interface) generated for you that is fairly invisible if
you're new to COM, and will make debugging harder IMO.

I think the rest of your question can be answered by saying that a managed
code reference to a Win32 COM object starts as a reference to its type
library, and then via a generated interop assembly (converted from the tlb)
and that's what your code calls. In Win32 COM Dlls the typelibrary is often
embedded in the Dll but it doesn't have to be.You don't need the actual COM
Dll to do development, just the type lib. Testing you need both of course.
However, if you're not using any Win32 code at all, and you are calling from
managed code to managed code then you're not expected to be using COM at
all, just normal Add Reference to an assembly. So the only actual COM
reference you can add is to the type library (and an interop assembly). I
don't believe managed code->interop assembly->CCW->managed code actually
works, so don't bother with COM at all if all your calls are managed code to
managed code.

--
Phil Wilson
The Definitive Guide to Windows Installer
http://www.apress.com/book/view/1590592972


"Milan" <Mi...@discussions.microsoft.com> wrote in message
news:023521B5-759E-43E9...@microsoft.com...

Milan

unread,
Nov 21, 2009, 10:54:01 AM11/21/09
to

Hi Wilson,

the "Type Library" is not always denoted with extension ".TLB", right ? so
how to know if something is type library or not ?
Is it possible from .TBL to generate manage assemblies for .NET ?
and do I have to register both .TBL and .dll files if .dll has actual C++
COM definition ?

BR,
Zoki

Wilson, Phil

unread,
Nov 23, 2009, 12:35:58 PM11/23/09
to
Type libraries are always .tlb, but many tools let you refer to a Win32 COM
DLL with its type library embedded in the resources.

Generating a managed assembly from a type library is exactly what tlbimp
does, the result being a COM interop assembly.

--
Phil Wilson
The Definitive Guide to Windows Installer
http://www.apress.com/book/view/1590592972


"Milan" <Mi...@discussions.microsoft.com> wrote in message

news:005FA8BB-C11C-411D...@microsoft.com...

0 new messages