Skip to content

Exception:算术运算导致溢出。 #886

@cuiliang

Description

@cuiliang

这不是一个HC的bug,但是应该可以在HC里加以规避处理。

现象
在个别人的电脑上会出现一个奇怪的异常:

OverflowException
   在 System.Windows.Shell.WindowChromeWorker._HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   在 System.Windows.Shell.WindowChromeWorker._WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   在 System.Windows.Interop.HwndSource.PublicHooksFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

相关信息
在StackOverflow上找到一个相关的帖子:
https://stackoverflow.com/questions/33287542/what-would-cause-wm-nchittest-lparam-to-overflow-a-32-bit-integer

里面有人贴了一个一个网址:
https://developercommunity.visualstudio.com/t/overflow-exception-in-windowchrome/167357

提到的解决方法:

protected override void OnSourceInitialized( EventArgs e )
      {
         base.OnSourceInitialized( e );
         ( (HwndSource)PresentationSource.FromVisual( this ) ).AddHook( HookProc );
      }
      private IntPtr HookProc( IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled )
      {
         if ( msg == 0x0084 /*WM_NCHITTEST*/ )
         {
            // This prevents a crash in WindowChromeWorker._HandleNCHitTest
            try
            {
               lParam.ToInt32();
            }
            catch ( OverflowException )
            {
               handled = true;
            }
         }
         return IntPtr.Zero;
      }

其它相关链接:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions