Windows Aero 表单错误
好的,所以我已经按照文档进行了最小的细节,当我尝试调试和运行(F5)时,它不断给我以下错误:
检测到 PInvokeStackImbalance 消息:对 PInvoke 函数的调用 'VistaControls!VistaControls.Dwm.NativeMethods::DwmExtendFrameIntoClientArea' 堆栈不平衡。这是 可能是因为托管 PInvoke 签名与非托管不匹配 目标签名。检查是否 调用约定和参数 PInvoke 签名与目标匹配 非托管签名。
我不知道这意味着什么,也不知道如何解决它!有人可以帮忙吗?有什么建议吗?
我以前用过这个,但这次不起作用。我正在使用 VS2010 Express C# WinForms、.NET 4(就像我很久以前第一次使用它时一样。)
谢谢
是的,我注意到了修正有人在该页面的底部做了修改,我修复了它,但它仍然不起作用!
代码:
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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过恢复到 .NET 3.5,您只是隐藏了问题:堆栈不平衡仍然存在,您只是没有从负责检测正确的 P/Invoke 调用的托管调试助手中得到任何异常,原因我不知道。
“Windows Forms Aero”库中的
DwmExtendFrameIntoClientArea
签名是错误的。这是原始的非托管签名:
这是库中的签名:
虽然乍一看它似乎与非托管签名匹配,但事实并非如此。
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:
Here is the signature in the library:
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 bevoid
and notint
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.没关系。我得到了它。很遗憾这不适用于 .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*.