tags:

views:

553

answers:

3

I'm writing a C# wrapper for a third-party native library, which we have as a DLL. I would like to be able to distribute a single DLL for the new assembly. Is it possible for me to embed the win32 DLL in my .NET DLL, and still make calls into it using P/Invoke? If so, how?

+1  A: 

I don't think you can do it directly, but it's possible to extract it at runtime to some temporary location and make call to that copy.

Mehrdad Afshari
+1  A: 

Should work, if the native dll does not have any dependencies.

You can compile the dll in as embedded resource, than access the stream from inside your code, serialize it to the temporary folder and use it from there.

Too much to post example code here, but the way is not to complicated.

BeowulfOF
+1  A: 

I've never done it but I know of an opensource project that does this. They embed the native SQLite3 code into the managed SQLite assembly using their own tool called mergebin.

Go and take a look at the SQLite project for .NET by PHX and grab the source and you can see how it's done.

HTH
Kev

Kev