“Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call” after successful C# callback from the C++ code

前端 未结 2 1156
礼貌的吻别
礼貌的吻别 2020-12-22 07:52

I\'m making a C# application which is using GameSpy C code (the GP part). The C code is calling a callback (which is C# code) succesfully, but I get this error Run-Tim

相关标签:
2条回答
  • 2020-12-22 08:00

    Check the calling conventions you are using.

     [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
    

    Reference to other related question: Callback from C function - crash

    0 讨论(0)
  • 2020-12-22 08:17

    Problem solved unexpectedly my myself (after 5 hours googling). I suspected a wrong calling convention already, but I didn't know how to switch it correctly. I've changed it in the C code as suggested here (http://computerarts.com.cn/dotnet-tech/1691/):

    // GPCallback
    /////////////
    //__declspec(dllexport) typedef void (* GPCallback)(
    //typedef __declspec(dllexport) void (* GPCallback)(
    typedef void (_stdcall * GPCallback)(
      GPConnection * connection,
      void * arg,
      void * param
    );
    
    0 讨论(0)
提交回复
热议问题