0

Was wondering if anyone would be so kind to point me in the right direction on how to call a third party's C++ DLL in C#. The API is closed source but the header files are available. I've read up on using P/Invoke but after further diving, it's leading to marshalling very complex data structures across, and that's IF I can do the declarations for the third party classes/functions.

If there's any reading material / tutorials out there you can recommend or just point me in the right direction, I would appreciate it.

Thanks so much in advance

Jack
  • 5
  • 1
  • 3
  • I would recommend reading the suggestions / question in http://stackoverflow.com/questions/2495632/easiest-way-to-generate-p-invoke-code – MDR Oct 29 '13 at 20:42

1 Answers1

0

I found http://www.pinvoke.net/ to be very helpful.

Also the http://clrinterop.codeplex.com/releases/view/14120

Additionally, what I did that I found helpful was to do a test solution. Start off with making a C# console app that initially does nothing, then make another Project (File, New, Project, Visual C++, Win32 Console Application) When the Wizard appears, choose DLL, Export symbols, (ATL and/or MFC if you need that).
When the Project appears, compile it as is and copy the DLL to you output folder of you C# Project Use the P/Invoke Interop Assistant to generate the C# method based on the header (I'd start with the function that takes no params and returns an int.) then call that from your C# console app.
Once I'd established how it worked with something really simple it was much easier to expand a bit at a time.
Try writing the C# calls yourself and then use the P/Invoke Interop Assistant to double check. Best wishes.