Unbalanced Stack!

后端 未结 3 490

I have written a VC++ dll. The declaration for one of the methods in the dll is as follows:

extern \"C\" _declspec(dllexport)
void startIt(int number)
{
             


        
相关标签:
3条回答
  • 2020-12-11 05:18

    When you p/invoke an external function, the calling convention used defaults to __stdcall. Since your function uses the __cdecl convention, you need to declare it as such:

    [DllImport("Tracking.dll", EntryPoint = "startIt",
        CallingConvention = CallingConvention.Cdecl)]
    public extern static void startIt(int number);
    
    0 讨论(0)
  • 2020-12-11 05:23

    Could you be missing CallingConvention=CallingConvention.Cdecl in your DllImport attribute?

    0 讨论(0)
  • 2020-12-11 05:41

    Constantin and Frederic Hamidi have answered this question correctly as to how to fix this problem. This can help avoid an eventual stack overflow. I have bitten by this several times myself. What is really at play here is that .NET 4 has enabled a managed debugging assistant for debug (not release) builds on 32 bit x86 machines (not 64 bit ) that checks for an incorrectly specified p/invoke call. This MSDN article details this : http://msdn.microsoft.com/en-us/library/0htdy0k3.aspx. Stephen Cleary deserves the credit for identifying this on this post: pinvokestackimbalance -- how can I fix this or turn it off?

    0 讨论(0)
提交回复
热议问题