Question

I am trying to implement a COM interface in my C# dll for others to consume. I have defined an interface in foo.idl.

I've run foo.idl through tlbimp to produce foo.dll, a .Net assembly. Now to implement my interface, I can reference foo.dll in my dll to implement the interface.

This works perfectly as it stands with one exception: I now have to distribute two dlls instead of one. This actually goes against the requirements of the project I'm working on: deliver one DLL.

Is there a way to merge the tlbimp dll into mine, or any other way to do this (implement a COM interface in C# without the second dll)?

Was it helpful?

Solution

A good disassembler gets the job done, like Reflector. You can simply disassemble the interop assembly and copy the generated C# interface declarations into your source code. Of course you should only do this if the interface declarations and IIDs are stable.

And definitely consider upgrading to VS2010. Its "embed interop types" feature allows you to ship your assembly without the interop assembly.

OTHER TIPS

You could probably cheat by using a .tlb instead of the 'glue' dll.

I'd suggest you create a mixed-mode assembly using MSVC++/CLR

This might have the drawback that you can't use C# in the same assembly. Should you want to add C# code to the mix, you might be able to squeeze out of your tough situation using

For other, possibly interesting, thoughts see my earlier answer:

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