kpeng163 2022-04-29 10:56 采纳率: 50%
浏览 59
已结题

SetWindowLong调用 堆栈不一致

一个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 就可以。但实际还是报错,不知道原因出在哪里。

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 5月7日
    • 修改了问题 4月29日
    • 创建了问题 4月29日

    悬赏问题

    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line