22.12.08

Using C# delegates to call C++ functions and get a string back

C# delegate stuff:
public delegate void MyFuncDelegate(string sIn, StringBuilder sOut); public event MyFuncDelegate MyFuncEvent;
C++ prototype:
static void MyFunc(LPCTSTR sIn, LPTSTR sOut);
Tie them together with:
public void RegisterDelegateMyFunc(IntPtr ptrCallback) { MyFuncDelegate d = Marshal.GetDelegateForFunctionPointer(ptrCallback,typeof(MyFuncDelegate)) as MyFuncDelegate; if (d != null) { MyFuncEvent += d; } }

0 comments:

Post a Comment