Windows Aero Forms Errors

Ok, so I followed the documents down to the smallest detail, and it continues to give me the following error when trying to debug and start (F5):

PInvokeStackImbalance detected Message: Calling PInvoke 'VistaControls! VistaControls.Dwm.NativeMethods :: DwmExtendFrameIntoClientArea 'has an unbalanced stack. This is likely because the PInvoke managed signature does not match the unmanaged target signature. Ensure that the calling agreement and parameters of the PInvoke signature match the target unmanaged signature.

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

I have used this before, but this time it does not work. I am using VS2010 Express C # WinForms, .NET 4 (As before, when I first used it many years ago.)

thanks

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

And yes, I noticed a fix that the person made at the bottom of this page, and I fixed it, but it still doesn't work!

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); } } } 
+4
source share
2 answers

Back in .NET 3.5, you just hid the problem: the stack imbalance is still present, you just don't get any exceptions from the debug administration assistant, which is responsible for finding the right P / Invoke calls for an unknown reason to me.

Invalid DwmExtendFrameIntoClientArea signature in the Windows Forms Aero library.

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); 

Although it seems like it is uncontrollable at first glance, it is not. PreserveSig = false tells the CLR to interpret the returned HRESULT and automatically throw an exception if it matches an error (see PreserveSig on MSDN ). The return type of the function must be void , not int anymore, since the result has already been consumed from the stack at run time.

Change to PreserveSig = true in the library code, and the stack imbalance will disappear.

+6
source

Nothing. I understood. It is so embarrassing that it does not work with .NET 4!

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

-1
source

Source: https://habr.com/ru/post/1340432/


All Articles