bwells Posted April 6, 2003 Posted April 6, 2003 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 Quote
*Gurus* Derek Stone Posted April 6, 2003 *Gurus* Posted April 6, 2003 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. Quote Posting Guidelines
bwells Posted April 6, 2003 Author Posted April 6, 2003 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? Quote
*Gurus* Derek Stone Posted April 6, 2003 *Gurus* Posted April 6, 2003 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. Quote Posting Guidelines
bwells Posted April 6, 2003 Author Posted April 6, 2003 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! Quote
Ariez Posted April 8, 2003 Posted April 8, 2003 have you tried the tlbimp to wrap your dll? Quote Auto-suggestion: "I have a life" Uncontroled thinking: "So what the.."
Ariez Posted April 8, 2003 Posted April 8, 2003 forget it, it only works with type libraries..sorry Quote Auto-suggestion: "I have a life" Uncontroled thinking: "So what the.."
Recommended Posts