Is there any possibility in converting an unmanaged DLL into a managed DLL?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Wrapper classes
You can write a wrapper class for the DLL. These are quite popular. Third-party library providers usually provide such wrapper .NET assemblies that wrap their DLL API (written in C++, C etc.)
In your wrapper class, just
DllImportall the API functions in the library DLL. Then you can use those functions just like any .NET class method.However, in practice you’ll sometimes have to write your own .NET-compliant methods that call those imported functions, because of argument types mapping and other checkings you’ll want to provide.
Also consider providing convenient overloaded methods because CLR supports them and not all non-managed libraries do.
COM Interop
Or, if that unmanaged DLL is a COM module and you just want to use it as is, and if you are using Visual Studio, you can simply “Add Reference” to it and Visual Studio will automatically create an Interop wrapper class for you.
Type library import
If your unmanaged DLL is not a COM module, but you still want to have it automatically convert into a CLR-compliant assembly (without having to write a wrapper class), you must document all the API functions in an IDL file. Usually, if your library is a C++ or C DLL, they’ll have header files in C++/C source format which can be readily refactored into an IDL file (which uses C syntax). Then use
midlto create a type library for that DLL. You can then convert that type library into a .NET assembly withtlbimp.