开发者

Form.FormBorderStyle Native Exception Access violation

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 visibl开发者_如何学JAVAe.

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.


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜