4 .net c# windows aero winforms
好的,所以我跟着文档一直到最小的细节,当我尝试调试并运行时,它一直给我以下错误(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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
通过恢复到.NET 3.5,您只是隐藏了问题:堆栈不平衡仍然存在,您只是没有从负责检测正确的P/Invoke调用的托管调试助手中获得任何异常,原因我不知道.
DwmExtendFrameIntoClientArea"Windows Forms Aero"库中的签名是错误的.
这是原始的非托管签名:
HRESULT WINAPI DwmExtendFrameIntoClientArea(HWND hWnd, __in const MARGINS *pMarInset);
Run Code Online (Sandbox Code Playgroud)
这是图书馆的签名:
[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMarInset);
Run Code Online (Sandbox Code Playgroud)
虽然它似乎与乍看之下的非管理型相匹配,但事实并非如此.PreserveSig = false告诉CLR解释返回的HRESULT并在错误对应时自动抛出异常(参见MSDN上的PreserveSig).函数返回类型必须是void,而int不再是,因为运行时已经从堆栈中消耗了结果.
更改为PreserveSig = true库代码并且堆栈不平衡将消失.