using unmanaged DLL class

bwells

Well-known member
Joined
Feb 25, 2003
Messages
84
I have written an unmanaged DLL that contains a class. I want to instantiate and call methods on this class from my managed C# program. I have only been able to find ways to call unmanaged functions, but not a way to maintain state in the DLL using an object.

How can I call (non-static) methods on a class in an unmanaged DLL from a managed C# application?

thanks
Bryan
 
From within Visual Studio .NET open up the Solution Explorer and right-click on the current project. Select "Add Reference...". Select the "COM" tab and hit "Browse...". Locate your COM DLL and select "Open". Hit "OK" and youre all set. Create an instance of one of the DLLs classes the same as you would a .NET class (Assembly.Class). Intellisense should make it fairly easy.
 
My unmanaged DLL is not a COM DLL. Do I need to make it a COM DLL for what you are suggesting? Is this an easy task?
 
Since you mentioned that you wished to instantiate an instance of a class I assumed you were referring to a COM DLL, since COM is the de facto standard of communication amongst components in Windows. What kind of DLL are you creating? I can only assume now that its a standard Win32 DLL, for lack of any other likely options.
 
Yes, this is a Win32 DLL. Its a basic class that supports communication to some special hardware via a device driver. The device driver is written in "C", and I wrote a wrapper class in C++ to provide a better abstraction for the driver. Now I want to access the hardware from a C# application using the (unmanaged) DLL.


I learned on the Microsoft site about creating a proxy using c++ with managed extensions. I tired this and it worked out very well. My C++ proxy class talks directly to the DLL, and acts as a proxy for the unmanaged DLL. Now I can load the C++ with managed extensions DLL from C# and everything seems to be happy.

I would always welcome any additional advice you can offer!
 
Back
Top