“Overflow or underflow in the arithmetic operation” WPF specific issue

后端 未结 3 2135
遇见更好的自我
遇见更好的自我 2020-12-10 06:18

My WPF test app (very simple, just one window) is using a 3rd party managed dll (say X.dll). This managed dll uses some unmanaged dll\'s . So lets say I write a small wpf a

3条回答
  •  无人及你
    2020-12-10 06:45

    Following the link from @Mishhl the fix is

    public class FloatingPointReset
    {
        [DllImport("msvcr110.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int _fpreset();
    
    
        public static void Action()
        {
            // Reset the Floating Point (When called from External Application there was an Overflow exception)
            _fpreset();
        }
    }
    

    It's caused by something in an included DLL resetting the FP into a state that isn't compatible with WPF/C#/Microsoft DLL's. Delphi/CPPB does this by default.

    So in either the window constructor or App() constructor just do

    FloatingPointReset.Action();
    

    You may need to change the following to reference any version of msvcr###.dll

    [DllImport("msvcr110.dll", CallingConvention = CallingConvention.Cdecl)]
    

    e.g.

    [DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]
    

提交回复
热议问题