Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows Aero窗体错误_C#_.net_Windows_Winforms_Aero - Fatal编程技术网

C# Windows Aero窗体错误

C# Windows Aero窗体错误,c#,.net,windows,winforms,aero,C#,.net,Windows,Winforms,Aero,好的,所以我一直关注文档的细节,当我尝试调试和运行(F5)时,它总是给我以下错误: 检测到PinvokesTack不平衡 消息:调用PInvoke函数 “VistaControl!VistaControl.Dwm.NativeMethods::DwmExtendFrameIntoClientArea' 使堆栈不平衡。这是 很可能是因为那只松鼠 签名与非托管签名不匹配 目标签名。检查 调用约定和参数 PInvoke签名与目标匹配 非托管签名 我不知道这意味着什么,也不知道如何修复它!有人能帮忙吗?

好的,所以我一直关注文档的细节,当我尝试调试和运行(F5)时,它总是给我以下错误:

检测到PinvokesTack不平衡 消息:调用PInvoke函数 “VistaControl!VistaControl.Dwm.NativeMethods::DwmExtendFrameIntoClientArea' 使堆栈不平衡。这是 很可能是因为那只松鼠 签名与非托管签名不匹配 目标签名。检查 调用约定和参数 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);
        }
    }
}

没关系。我得到了它。太遗憾了,这不适用于.NET4


您需要转到项目属性,并通过还原到.NET 3.5将其从.NET Framework 4更改为3.5或更低版本*

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

“Windows窗体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,并在异常与错误相对应时自动抛出异常(请参阅)。函数返回类型必须是
void
而不是
int
,因为运行时已经从堆栈中使用了结果


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

它似乎告诉您
dwmextendframeintoclienterea
函数的p/Invoke定义有问题,但是你需要发布你当前的定义,以便任何人告诉你必须修复它。我有根据地猜测,当
IntPtr
应该被使用时,就会使用
int
。@Cody Gray;这个问题现在已经解决了,但我还是会在问题的底部发布我的代码。Thank you.PreserveSig=false在这里不是一个坏主意,它会在函数失败时自动生成异常。但一定要将返回类型更改为“void”。否则,请确保自己引发异常。您完全正确,但是库已经在检查返回值并引发自定义异常,因此这里的PreserveSig=true应该足够了,即使通常最好将其设置为false。