Question

I have a COM DLL written in unmanged C++, and compiled with VS 2010. I can register the DLL using regsvr32 and I can invoke it via VBscript.

When I try to add a reference to it, while creating a C# client, I don't see the COM object listed in Add Reference -> COM tab. If I manually browse to the DLL and try to select it, it says that the DLL is not a valid assemlby or COM component.

Now, I can use tlbimp tool to generate an interop DLL and use that to add as a reference to my C# client. And everything works fine.

My questions are:

  1. Why the original COM is not listed in COM tab in Add Reference dialog when it's registered via regsvr32?
  2. Why does VS IDE think that it's not a valid COM when I can invoke it from VBScript and C++ native code?
  3. What exactly does tlbimp do which the IDE can't do?
  4. What do I need to read further to improve my understanding of the type libraries and interoperability at play here?
Was it helpful?

Solution

Looks like a typelib issue -- your COM classes may be have been registered correctly, but your typelib probably is not. Maybe you forgot to invoke RegisterTypeLib from within your DllRegisterServer function?

Referring to your questions:

  1. The dialog looks for registered typelibs, not for COM classes

  2. VBscript invokes IDispatch and does not care about typelibs. tlbimp does not care about IDispatch and requires a typelib

  3. You passed the DLL name to tlbimp -- so tlbimp knew how to get hold of the typelib. VS, in contrast, refers to the registry which lacks the approriate registration data

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top