Windows Aero 表单错误

发布于 2024-10-18 10:31:27 字数 1790 浏览 1 评论 0原文

好的,所以我已经按照文档进行了最小的细节,当我尝试调试和运行(F5)时,它不断给我以下错误:

检测到 PInvokeStackImbalance 消息:对 PInvoke 函数的调用 'VistaControls!VistaControls.Dwm.NativeMethods::DwmExtendFrameIntoClientArea' 堆栈不平衡。这是 可能是因为托管 PInvoke 签名与非托管不匹配 目标签名。检查是否 调用约定和参数 PInvoke 签名与目标匹配 非托管签名。

我不知道这意味着什么,也不知道如何解决它!有人可以帮忙吗?有什么建议吗?

我以前用过这个,但这次不起作用。我正在使用 VS2010 Express C# WinForms、.NET 4(就像我很久以前第一次使用它时一样。)

谢谢

链接:http://windowsformsaero.codeplex.com/wikipage?title=Glass%20on%20WinForms&referringTitle=Documentation

是的,我注意到了修正有人在该页面的底部做了修改,我修复了它,但它仍然不起作用!

代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VistaControls.Dwm;

namespace One_Stop_Management
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.FillRectangles(Brushes.Black, new Rectangle[] {
        new Rectangle(0, 0, this.ClientSize.Width, 30),
        new Rectangle(this.ClientSize.Width - 30, 0, 30, this.ClientSize.Height),
        new Rectangle(0, this.ClientSize.Height - 30, this.ClientSize.Width, 30),
        new Rectangle(0, 0, 30, this.ClientSize.Height)
    });
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            VistaControls.Dwm.DwmManager.EnableGlassSheet(this);
        }
    }
}

Okay, so I have followed the docs right down to the smallest detail, and it keeps giving me the following error when I try to debug and run (F5):

PInvokeStackImbalance was detected
Message: A call to PInvoke function
'VistaControls!VistaControls.Dwm.NativeMethods::DwmExtendFrameIntoClientArea'
has unbalanced the stack. This is
likely because the managed PInvoke
signature does not match the unmanaged
target signature. Check that the
calling convention and parameters of
the PInvoke signature match the target
unmanaged signature.

I have no idea what this means, or how to fix it! Can somebody please help? Any suggestions?

I have used this before but it's not working this time. I am using VS2010 Express C# WinForms, .NET 4 (As I was before when I first used it ages ago.)

Thank you

Link: http://windowsformsaero.codeplex.com/wikipage?title=Glass%20on%20WinForms&referringTitle=Documentation

And yep, I have noticed the correction a person made down the bottom of that page, and I fixed that up, but it still doesn't work!

The Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VistaControls.Dwm;

namespace One_Stop_Management
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            e.Graphics.FillRectangles(Brushes.Black, new Rectangle[] {
        new Rectangle(0, 0, this.ClientSize.Width, 30),
        new Rectangle(this.ClientSize.Width - 30, 0, 30, this.ClientSize.Height),
        new Rectangle(0, this.ClientSize.Height - 30, this.ClientSize.Width, 30),
        new Rectangle(0, 0, 30, this.ClientSize.Height)
    });
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            VistaControls.Dwm.DwmManager.EnableGlassSheet(this);
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阳光①夏 2024-10-25 10:31:27

通过恢复到 .NET 3.5,您只是隐藏了问题:堆栈不平衡仍然存在,您只是没有从负责检测正确的 P/Invoke 调用的托管调试助手中得到任何异常,原因我不知道。

“Windows Forms Aero”库中的DwmExtendFrameIntoClientArea签名是错误的。

这是原始的非托管签名:

HRESULT WINAPI DwmExtendFrameIntoClientArea(HWND hWnd, __in  const MARGINS *pMarInset);

这是库中的签名:

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset);

虽然乍一看它似乎与非托管签名匹配,但事实并非如此。 PreserveSig = false 告诉 CLR 解释返回的 HRESULT,并在对应于错误时自动抛出异常(请参阅 MSDN 上的 PreserveSig)。函数返回类型必须是 void 而不是 int,因为结果已被运行时从堆栈中消耗掉。

在库代码中更改为 PreserveSig = true ,堆栈不平衡现象就会消失。

By reverting to .NET 3.5 you just hid the problem: the stack imbalance is still present, you just don't get any exception from the Managed Debugging Assistant that is responsible for detecting correct P/Invoke calls, for a reason unknown to me.

The signature of DwmExtendFrameIntoClientArea in the "Windows Forms Aero" library is wrong.

Here is the original unmanaged signature:

HRESULT WINAPI DwmExtendFrameIntoClientArea(HWND hWnd, __in  const MARGINS *pMarInset);

Here is the signature in the library:

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset);

While it seems to match the unmanaged one at first sight, it isn't. PreserveSig = false tells the CLR to interpret the returned HRESULT and automatically throw an exception if it's corresponding to an error (see PreserveSig on MSDN). The function return type must be void and not int anymore, since the result has already been consumed from the stack by the runtime.

Change to PreserveSig = true in the library code and the stack imbalance will be gone.

乄_柒ぐ汐 2024-10-25 10:31:27

没关系。我得到了它。很遗憾这不适用于 .NET 4!

您需要转到“项目属性”,并将其从 .NET Framework 4 更改为 3.5 或更低版本*。

Never mind. I got it. It's such a shame this doesn't work with .NET 4!

You need to go to Project Properties, and change it from .NET Framework 4 to 3.5 or lower*.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文