PInvokeStackImbalance Excpetion

If you get a PInvokeStackImbalance exception it could be:

  • One parameter has a wrong type (p. x. int changed to long)
  • The CallingConvention of the DllImport. Change it in the declaration:
    [DllImport("user32.dll", EntryPoint="SetWindowLongA", SetLastError=true)]
    		private static extern long SetWindowLong (IntPtr hwnd, int nIndex, long dwNewLong);
    

    for example to

    [DllImport("user32.dll", EntryPoint="SetWindowLongA", SetLastError=true, CallingConvention = CallingConvention.Cdecl)]
    		private static extern long SetWindowLong (IntPtr hwnd, int nIndex, long dwNewLong);
    

Leave a comment

Your email address will not be published. Required fields are marked *