Interop question  
Author Message
Freqy





PostPosted: Common Language Runtime, Interop question Top

Hi all,

I'm trying to use an open source library in my C# project. At present all I can make is a .lib file. I'm looking for a way to incorporate this into my project without doing huge amounts of coding and/or reworking of the original project.

I'm a newbie with all of this, so I *think* I'm looking for a way to compile the .lib as a managed library, or to create a managed wrapper for the library. I don't really know though, so please feel free to post any suggestions, good reading or crazy ideas you have.

Thanks in advance.




.NET Development6  
 
 
Mattias Sjogren





PostPosted: Common Language Runtime, Interop question Top

Create a managed C++ library that links with the LIB file.



 
 
nobugz





PostPosted: Common Language Runtime, Interop question Top

No, the .NET 1.1 runtime doesn't know how to load a .NET 2.0 assembly. The format has changed. Both the .NET 2.0 runtime and VS2005 know how to deal with a .NET 1.1 assembly. Converting your VS2003 project to VS2005 is easy too. COM is an option but a mighty ugly one.


 
 
Nikhil Rajwade





PostPosted: Common Language Runtime, Interop question Top

The COM component is running inprocess with iexplore.exe and is not shared with other instances of the browser. To be able to create a singleton register your COM component in COM+ (outof process singleton). However this may not be the ideal way to share state. You should look at other alternatives like Named Pipes/Remoting/Database/MSMQ etc.

 
 
Freqy





PostPosted: Common Language Runtime, Interop question Top

To clarify the above response (now that I have solved the problem)

Open the solution in question in VCPP, create a new CLR DLL project. Add the location of the solution's LIB file to your linker inputs. Now create a class with methods that call on the libary's functions. You will have to do some very freaky stuff with things like turning char* into System::String^ in order to get a C# string, and also with things like typedef-ed enums and structs - I'm writing classes to mirror these so I can return them as args from my managed DLL and use them straight up in C#.

Hope this helps someone.



 
 
Paul_Sharlyr





PostPosted: Common Language Runtime, Interop question Top

Thank you Hans, that helps. I appreciate your response, it at least saves me a lot of frustration!

Kind regards,
-Paul