Answered by:
How do I load an unmanaged DLL file using C#

Question
-
I'm using VS2010, .Net 4.0 and C#. I'm looking to find some example code to load an unmanaged DLL file and use the functions within it. The DLL files were created with a previous version of Visual Studio but not using .Net. and using C++. Any help would be appreciated.Sunday, February 3, 2013 4:10 PM
Answers
-
Hi Tncoder,
Welcome to the MSDN Forum.
Please try the interop: http://msdn.microsoft.com/en-us/library/kew41ycz(v=vs.100).aspx
Or this way:
http://msdn.microsoft.com/en-us/library/aa984739(v=vs.71).aspx
Here is a code project sample: http://www.codeproject.com/Articles/11310/DLLImport-with-dynamically-bound-native-DLLs-using
I hope it will be helpful.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Tuesday, February 5, 2013 10:44 AM -
Thanks for your help. I had the owner of the dll files recompile them using .Net and VS2010. Thanks again for your help.
- Marked as answer by tncoder Thursday, February 14, 2013 7:03 PM
Thursday, February 14, 2013 7:03 PM
All replies
-
You would use LoadLibrary() to load a DLL, then use GetProcAddress() to obtain the address of the functions to invoke, then use FreeLibrary() to remove the DLL from memory once you are done.
But why do you want to do all this? You can simply declare the function entry points via P/Invoke and the .net runtime will take care of the loading part of the library (and maybe even unloading, I don't know and I don't care as it is rarely ever needed).
Jose R. MCP
Code SamplesSunday, February 3, 2013 9:12 PM -
Hi Tncoder,
Welcome to the MSDN Forum.
Please try the interop: http://msdn.microsoft.com/en-us/library/kew41ycz(v=vs.100).aspx
Or this way:
http://msdn.microsoft.com/en-us/library/aa984739(v=vs.71).aspx
Here is a code project sample: http://www.codeproject.com/Articles/11310/DLLImport-with-dynamically-bound-native-DLLs-using
I hope it will be helpful.
Best regards,
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Tuesday, February 5, 2013 10:44 AM -
Thanks for your help. I had the owner of the dll files recompile them using .Net and VS2010. Thanks again for your help.
- Marked as answer by tncoder Thursday, February 14, 2013 7:03 PM
Thursday, February 14, 2013 7:03 PM