Hi All,
I have a problem with found a bug here. Maybe someone can help me. From c# I call a c++ function (in dll via P/Invoke). One function give a handle form manage code to a unmanage code. Next after call another function from manage code unmanage call this callback in manage. In c# it is look like:
Unmanage part:Code:[DllImport("tttddd.dll", CharSet = CharSet.Ansi)] public static extern void CallBackFire(); public delegate void InterfaceGroupEvent([MarshalAs(UnmanagedType.LPStr)] string ord); [DllImport("tttddd.dll", CharSet = CharSet.Ansi)] public static extern void set_InterfaceGroupEventCallback(InterfaceGroupEvent f); private void button1_Click(object sender, EventArgs e) { set_InterfaceGroupEventCallback(InterfaceGroupEventCallbackFunction); CallBackFire(); } public void InterfaceGroupEventCallbackFunction( string str) { MessageBox.Show(str); }
All look to work good in runtime (message box is show) but next come a bug:Code:static const void*(*InterfaceGroupEventCallback)(char*); __declspec(dllexport)void set_InterfaceGroupEventCallback(const void*(*f)(char*)) { InterfaceGroupEventCallback=f; } __declspec(dllexport)void CallBackFire() { char *s=(char*)CoTaskMemAlloc(100); sprintf(s,"Cat"); InterfaceGroupEventCallback(s); }
"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. THis is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention"
But funtions look to have same conventions....
Any ideas ?
Thnx in advance
Olekba




Reply With Quote