Form.FormBorderStyle 本机异常访问冲突

发布于 2024-09-28 14:37:23 字数 1182 浏览 1 评论 0原文

在 WindowsCE 平台(自定义构建)上,我们的 C# gui 使用常规形式来显示“弹出菜单”。 我们将 FormBorderstyle 设置为 None,因为我们不希望表单控件可见。

一段时间后,一些客户报告了“灰盒”。 经过一些测试后,我们可以很快地重现该问题。当我们不断打开两个不同的菜单(表单)时,平台会向我们显示本机异常。

错误
发生了本机异常 在 Tiger.CEHost.exe 中。选择退出并 然后重新启动该程序,或选择 详细信息以获取更多信息。

详细信息:

错误
异常代码:0xC0000005
异常地址:0x00000001
读取:0x00000001

在 WL.SetSTyle(IntPtr hwnThis, UInt32 dwMask, UInt32 dwStyle)
在 Form._SetBorderStyle(AGL_WINDOWSTYLE wstyVal, AGL_WINDOWSTYLE wstyMask)
在 Form.set_FormBorderStyle(FormBorderStyle 值)
在 pDropDown.PopupForm.Show()
在 pDropDown.Show()
在 pButton.ShowHideDropDown()
在 pButton.OnClick(EventArgs e)
在 Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
在 Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
在 EVL.EnterMainLoop(IntPtr hwnMain)
在Application.Run(Form fm)
在 Program.Main(String[] args)

它似乎总是在 FormBorderStyle 属性处失败。我们已经尝试删除所有 pInvoke,因为某些内存可能被覆盖,但这没有帮助。

我们还记录对 Show 方法的每次调用,并且每次调用都是在 gui 线程中进行的,并且 Form 包含一个有效的句柄。

On a WindowsCE platform (custom build) our C# gui uses regular forms to show an "popup menu".
We set the FormBorderstyle to None as we don't want the form controls to be visible.

Some clients reported "Gray boxes" after a while.
After some testing here we could reproduce the problem quite fast. When we open 2 different menu's (forms) constantly the platform shows us an native exception.

Error
A native exception has occurred
in Tiger.CEHost.exe. Select Quit and
then restart this program, or select
Details for more information.

The details:

Error
ExceptionCode: 0xC0000005
ExceptionAdress: 0x00000001
Reading: 0x00000001

at WL.SetSTyle(IntPtr hwnThis, UInt32 dwMask, UInt32 dwStyle)
at Form._SetBorderStyle(AGL_WINDOWSTYLE wstyVal, AGL_WINDOWSTYLE wstyMask)
at Form.set_FormBorderStyle(FormBorderStyle value)
at pDropDown.PopupForm.Show()
at pDropDown.Show()
at pButton.ShowHideDropDown()
at pButton.OnClick(EventArgs e)
at Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
at Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at EVL.EnterMainLoop(IntPtr hwnMain)
at Application.Run(Form fm)
at Program.Main(String[] args)

It always seems to fail at the FormBorderStyle property. We've already tried to remove all the pInvokes as perhaps some memory was overwritten, but this didn't help.

We also log each call to the Show method and each call is made in the gui thread and the Form contains a valid handle.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请恋爱 2024-10-05 14:37:23

我从未见过这种情况,这往往让我认为这不太可能是 CF 甚至您的应用程序中的问题。

您的设备有足够的内存来运行该应用程序吗?内存不足的情况应该引发 OOM,但我见过它做了其他不太可预测的事情,所以它始终是首先要检查的事情。

如果内存不是问题,您确定这不是平台问题吗?请记住,由于操作系统的很大一部分是由 OEM 开发的,因此您不能排除操作系统中存在问题。

我会尝试两件事:

  1. 同一个应用程序在其他硬件(甚至模拟器)上运行正常吗?如果它在其他硬件上运行,则严重影响平台的问题。

  2. 由于使用 C# 中的小型应用程序进行重现相当容易,因此我建议使用 C/C++ 构建一个具有相同功能项目的应用程序,以查看其行为是否相同或是否会出现相同的问题。

I've never seen this, which tends to make me think that it's less likely to be a problem in the CF or even your app.

Does your device have enough memory to run the app? A low-memory condition should throw an OOM, but I've seen it do other, less predicatble things, so it's always the first thing to check.

If memory is not the issue, are you certain that it's not a platform problem? Remember, since a large portion of the OS is developed by the OEM, you can't rule out problems in the OS.

I'd try two things:

  1. Does the same app run fine on some other hardware (even the emulator) without problems? If it works on other hardware, it heavily implicates the platform as the problem.

  2. Since it's fairly easy to repro with a small app in C#, I'd recommend building an app in C/C++ that does the same functional items to see if it behaves or gives the same issue.

溺ぐ爱和你が 2024-10-05 14:37:23

这似乎是 netcfagl3_5.dll 中的一个错误(将通知 Microsoft 相关信息)

当我们使用 pinvokes (SetWindowLong) 设置 FormBorderstyle 时,我们无法重现该问题。

如果有人遇到这种罕见的错误,这是在不使用 .net FormBorderStyle 属性的情况下设置 formborderstyle 的代码。

private const uint WS_OVERLAPPED = 0x00000000;
        private const uint WS_POPUP = 0x80000000;
        private const uint WS_CHILD = 0x40000000;
        private const uint WS_MINIMIZE = 0x20000000;
        private const uint WS_VISIBLE = 0x10000000;
        private const uint WS_DISABLED = 0x08000000;
        private const uint WS_CLIPSIBLINGS = 0x04000000;
        private const uint WS_CLIPCHILDREN = 0x02000000;
        private const uint WS_MAXIMIZE = 0x01000000;
        private const uint WS_CAPTION = 0x00C00000;
        private const uint WS_BORDER = 0x00800000;
        private const uint WS_DLGFRAME = 0x00400000;
        private const uint WS_VSCROLL = 0x00200000;
        private const uint WS_HSCROLL = 0x00100000;
        private const uint WS_SYSMENU = 0x00080000;
        private const uint WS_THICKFRAME = 0x00040000;
        private const uint WS_GROUP = 0x00020000;
        private const uint WS_TABSTOP = 0x00010000;

        private const int WS_MINIMIZEBOX = 0x00020000;
        private const int WS_MAXIMIZEBOX = 0x00010000;

        private const uint WS_EX_DLGMODALFRAME = 0x00000001;
        private const uint WS_EX_NOPARENTNOTIFY = 0x00000004;
        private const uint WS_EX_TOPMOST = 0x00000008;
        private const uint WS_EX_ACCEPTFILES = 0x00000010;
        private const uint WS_EX_TRANSPARENT = 0x00000020;
        private const uint WS_EX_MDICHILD = 0x00000040;
        private const uint WS_EX_TOOLWINDOW = 0x00000080;
        private const uint WS_EX_WINDOWEDGE = 0x00000100;
        private const uint WS_EX_CLIENTEDGE = 0x00000200;
        private const uint WS_EX_CONTEXTHELP = 0x00000400;
        private const uint WS_EX_STATICEDGE = 0x00020000;

        private const int WS_EX_NOANIMATION = 0x04000000;
        public const int GWL_EX_STYLE = -20;
        public const int GWL_STYLE = (-16);

public static void SetNoBorder(Form form) {
            RemoveFormStyle(form, GWL_STYLE, (int)(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU));
            RemoveFormStyle(form, GWL_EX_STYLE, (int)(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
        }

public static void RemoveFormStyle(Form f, int modifier, int style) {
            int currStyle = GetWindowLong(f.Handle, GWL_EX_STYLE);
            currStyle &= ~style;
            SetWindowLong(f.Handle, modifier, currStyle);
        }

    [DllImport("Coredll.dll", SetLastError = true)]
    public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

    [DllImport("coredll.dll", SetLastError = true)]
    public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

It seems to be a bug in netcfagl3_5.dll (will notify Microsoft about this)

When we set the FormBorderstyle using pinvokes (SetWindowLong) we can't reproduce the problem.

In case someone experiences this rare bug, this is the code to set the formborderstyle without using the .net FormBorderStyle property.

private const uint WS_OVERLAPPED = 0x00000000;
        private const uint WS_POPUP = 0x80000000;
        private const uint WS_CHILD = 0x40000000;
        private const uint WS_MINIMIZE = 0x20000000;
        private const uint WS_VISIBLE = 0x10000000;
        private const uint WS_DISABLED = 0x08000000;
        private const uint WS_CLIPSIBLINGS = 0x04000000;
        private const uint WS_CLIPCHILDREN = 0x02000000;
        private const uint WS_MAXIMIZE = 0x01000000;
        private const uint WS_CAPTION = 0x00C00000;
        private const uint WS_BORDER = 0x00800000;
        private const uint WS_DLGFRAME = 0x00400000;
        private const uint WS_VSCROLL = 0x00200000;
        private const uint WS_HSCROLL = 0x00100000;
        private const uint WS_SYSMENU = 0x00080000;
        private const uint WS_THICKFRAME = 0x00040000;
        private const uint WS_GROUP = 0x00020000;
        private const uint WS_TABSTOP = 0x00010000;

        private const int WS_MINIMIZEBOX = 0x00020000;
        private const int WS_MAXIMIZEBOX = 0x00010000;

        private const uint WS_EX_DLGMODALFRAME = 0x00000001;
        private const uint WS_EX_NOPARENTNOTIFY = 0x00000004;
        private const uint WS_EX_TOPMOST = 0x00000008;
        private const uint WS_EX_ACCEPTFILES = 0x00000010;
        private const uint WS_EX_TRANSPARENT = 0x00000020;
        private const uint WS_EX_MDICHILD = 0x00000040;
        private const uint WS_EX_TOOLWINDOW = 0x00000080;
        private const uint WS_EX_WINDOWEDGE = 0x00000100;
        private const uint WS_EX_CLIENTEDGE = 0x00000200;
        private const uint WS_EX_CONTEXTHELP = 0x00000400;
        private const uint WS_EX_STATICEDGE = 0x00020000;

        private const int WS_EX_NOANIMATION = 0x04000000;
        public const int GWL_EX_STYLE = -20;
        public const int GWL_STYLE = (-16);

public static void SetNoBorder(Form form) {
            RemoveFormStyle(form, GWL_STYLE, (int)(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU));
            RemoveFormStyle(form, GWL_EX_STYLE, (int)(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE));
        }

public static void RemoveFormStyle(Form f, int modifier, int style) {
            int currStyle = GetWindowLong(f.Handle, GWL_EX_STYLE);
            currStyle &= ~style;
            SetWindowLong(f.Handle, modifier, currStyle);
        }

    [DllImport("Coredll.dll", SetLastError = true)]
    public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

    [DllImport("coredll.dll", SetLastError = true)]
    public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文