Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, February 6, 2014 12:48 PM
Hi All,
Greetings.
I have a c++ dll which have some methods. I would like to call the dll methods from my C# Windows application.
For that I need a wrapper class to communicate with C++ methods. How can i write a c# wrapper class for c++ dll.
Could you please provide a simple example to start with it.
Thanks,
Sathiya Jeba
All replies (2)
Thursday, February 6, 2014 1:40 PM ✅Answered
You need to use a technique called Platform Invoke, or PInoke, for short. You can find lots of tutorials, including the one at http://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx, by searching the Web for "pinvoke tutorial".
This example shows you how to use the DllImport attribute to output a message by calling puts
from msvcrt.dll
using System;using System.Runtime.InteropServices;class PlatformInvokeTest{ [DllImport("msvcrt.dll")] public static extern int puts(string c); [DllImport("msvcrt.dll")] internal static extern int _flushall(); public static void Main() { puts("Test"); _flushall(); }}
Thursday, February 6, 2014 2:43 PM ✅Answered
Try the pinvoke website www.pinvoke.net which has all the c# methods to call the windows system dlls.
jdweng