tags:

views:

275

answers:

5

Is there any open source tool for automatically generating .NET wrappers for a COM DLL library?

Thank you.

+1  A: 

You can try to use SWIG which is able to generate wrapper code for 18 languages. Also this MSDN article might be useful.

tobsen
+6  A: 

There is no wrapper necessary to use a COM object in .NET. In Visual Studio, right-click your project name in the Solution Explorer, and select "Add Reference." Any registered COM objects will be listed in the COM tab.

Interop wrappers are only necessary when using .NET assemblies as if they were COM objects - not the other way around as you have described in your question.

David Lively
I assume by his "open source" request he is -not- using Visual Studio.
Tj Kellie
Well, if he's using C# (in .NET as his question states, not in Mono, for instance), in ANY available version, he has access to VS. TlbImport has been mentioned elsewhere.
David Lively
+3  A: 

You can use the command line tool for the Type library import tool it will generate an interop assembly for you to use in your project.

The Type Library Importer converts the type definitions found within a COM type library into equivalent definitions in a common language runtime assembly.

If you are using VS.net you will be able to do this through the IDE. Otherwise I believe this tool is freely available (per your open-source request).

Tj Kellie
@David That is not necessarily true. Using the different command line arguments in TLBImport, you can change how the wrapper code gets generated. You can also use the tool to generate a PIA (Primary Interop Assembly). You can't do that with just the Add Reference in VS.
Nick
A: 

What about tlbimp typelib importer? MSDN documentation is here.

Hope this helps, Best regards, Tom.

tommieb75
+2  A: 

Yes, the source code for Tlbimp.exe is available. Download it from here...

Hans Passant
thx, that's what I was looking for (I want to customize the import process a bit)
Roman Plášil