一个winform程序,嵌入到一个外部exe程序中(把外部程序中的窗口作为父窗口)。但是父窗体会重绘我的窗体。
网上参考了一篇文章:https://www.cnblogs.com/helloj2ee/archive/2009/05/29/1491822.html
但实际使用的时候 报错
对 PInvoke 函数“SensorClient!SensorClient.Form1+Win32Support::SetWindowLong”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。
代码:
const int GWL_STYLE = -16;
const int WS_CLIPCHILDREN = 0x02000000;
class Win32Support
{
[DllImport("user32.dll", CharSet = CharSet.Auto,CallingConvention=CallingConvention.Cdecl)]
public static extern int SetWindowLong(IntPtr hwnd, int nlndex, int dwNewLong);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowLong(IntPtr hWnd, int nlndex);
}
int style = Win32Support.GetWindowLong(map.hwnd, GWL_STYLE);
style = style|WS_CLIPCHILDREN;
Win32Support.SetWindowLong(map.hwnd, GWL_STYLE, style);
网上说加上 CallingConvention=CallingConvention.Cdecl 就可以。但实际还是报错,不知道原因出在哪里。