Calling a class exported by a custom DLL in C#
-
Hi, I have a custom dll in C++ which exports a class with certain member functions. I want to call the methods from a c# application. I am able to call the member functions seperately using the DllImports[....]. Is it possible to instantiate an object of the exported class from the C# tester application? Kindly help. Is there any link which would give me this detail. Is the source code of the DLL necessary for this. Thanks, Regards, Vini
-
Hi, I have a custom dll in C++ which exports a class with certain member functions. I want to call the methods from a c# application. I am able to call the member functions seperately using the DllImports[....]. Is it possible to instantiate an object of the exported class from the C# tester application? Kindly help. Is there any link which would give me this detail. Is the source code of the DLL necessary for this. Thanks, Regards, Vini
If it where me, I would create a wrapper in Managed C++, then call that from c#. That way you could totally avoid DllImports. DllImports is fine and dandy for most functions, especially win32, but once you hit a function with some off the wall data structure it turns into a pain real quick. -Sam
-
Hi, I have a custom dll in C++ which exports a class with certain member functions. I want to call the methods from a c# application. I am able to call the member functions seperately using the DllImports[....]. Is it possible to instantiate an object of the exported class from the C# tester application? Kindly help. Is there any link which would give me this detail. Is the source code of the DLL necessary for this. Thanks, Regards, Vini
You can do this using a class factory and the
CallingConvention.ThisCall
calling-convention. See the CallingConvention enumeration[^] documentation for a little information about the various calling conventions and how they're used, and a previous post of mine about how to use it: http://www.codeproject.com/script/comments/forums.asp?msg=771919&forumid=1649&XtraIDs=1649&searchkw=ThisCall&sd=11%2F15%2F1999&ed=4%2F12%2F2004#xx771919xx[^].Microsoft MVP, Visual C# My Articles