好的,我一直跟踪文档直到最小的细节,当我尝试调试和运行(F5)时,它一直给我以下错误:
检测到PInvokeStackImbalance消息:对PInvoke函数PInvoke函数的调用不平衡堆栈。这可能是因为托管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);
}
}
}发布于 2011-02-19 12:20:03
通过恢复到.NET 3.5,您只是隐藏了问题:堆栈不平衡仍然存在,您只是没有从负责检测正确的P/Invoke调用的托管调试助手那里得到任何异常,原因我不知道。
"Windows“库中的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,堆栈不平衡就会消失。
发布于 2011-02-19 11:40:06
不要紧。这样啊,原来是这么回事。这太可惜了,.NET 4不起作用!
您需要转到Properties,并将其从.NET Framework4改为3.5或更低版本。
https://stackoverflow.com/questions/5050526
复制相似问题