C# PInvoke with struct contains function pointer
I struggled this for a while, still not able to figured out how to write code in C# sideC++ DLL
typedef void (WINAPI *P_HelloWorld)(void);
typedef struct {
P_HelloWorld pHelloWorld;
}FUNC_PARAM;
void Func4(FUNC_PARAM* pFunc)
{
pFunc.pHelloWorld();
}
C# Side:
public delegate void P_HelloWord();
[StructLayout(LayoutKind.Sequential)]
public struct FUNC_PARAM
{`enter code here`public P_HelloWord pHelloWorld;
}
[DllImport("EMV_DLL.dll")]
public extern static void Func4(FUNC_PARAM[] pFunc);
void main()
{
FUNC_PARAM g;
g.pHelloWorld = new P_HelloWord(this.myHelloWorld);
Func4(new FUNC_PARAM[] { g });
}
void myHelloWorld()
{
MessageBox.Show("My Hello World");
}
The above C# code doesn't work, when execute Func4 function, it throws out of memory exception.
Anybody could help me?
补充:.NET技术 , C#