Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Gurus*
Posted
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 you're all set. Create an instance of one of the DLL's classes the same as you would a .NET class (Assembly.Class). Intellisense should make it fairly easy.
  • *Gurus*
Posted
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 it's a standard Win32 DLL, for lack of any other likely options.
Posted

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!

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...