检测到PInvokeStackImbalance错误

时间:2014-09-07 08:31:28

标签: c#

我需要将以下代码从.c移植到c#。

typedef void (*CALLBACKERROR)(const char * ErrorString, int ErrorNum);
void WINAPI SetCallbackError (CALLBACKERROR CallbackError);

我试过以下代码:(使用已编译的c代码的DLL) 辩护:

public delegate void MyCallback(String str, int a);
[DllImport(LibName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern void SetCallbackError(MyCallback myCallback);

public void PrintCallbackError(String str, int a)
{
  Console.WriteLine("issue was detected");
}

Public void CheckConnection()
{
      SetCallbackError(PrintCallbackError);  -causes 1st exception
      OpenConnection(false);  - causes 2nd exception
…
}

第一个例外: enter image description here

第二个例外: enter image description here

出现以避免第二个例外的解决方案是将签名更改为根本没有获得任何参数 - 没有多大意义 - 但是有效... 辩护:

    public delegate void MyCallback();
public static void PrintCallBackError()

重要的是要说我不能改变c代码的实现。 我将不胜感激任何帮助和其他编码解决方案,

感谢提前 -

0 个答案:

没有答案
相关问题