System.ArithMeticeXception exception solution after .NET uses COM components.

xiaoxiao2021-03-06  14

Recently developed a .NET program, which involves the call to the COM component. After the call is used, if you use some small test programs to continue running, everything is normal, but when you use the GUI's FORM program, always appear, The following exception Exception: system.AithmeticexceptionMessage: Overflow or underflow occurs in the arithmetic operation. Source: System.Drawing at System.Drawing.Font.Initialize (FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont) at System.Drawing.Font..ctor (String familyName, Single emSize, FontStyle style , GraphicsUnit unit, Byte gdiCharSet) at Payment.Phone.ErrorForm.InitializeComponent () in E: /cvsroot/develope/payment/Phone/ErrorForm.cs: line 108 at Payment.Phone.ErrorForm..ctor (util util, String msg ) in E: /cvsroot/develope/payment/Phone/ErrorForm.cs: line 139 at Payment.Phone.ConfirmForm.lblNext_Click (Object sender, EventArgs e) in E: /cvsroot/develope/payment/Phone/ConfirmForm.cs: LINE 212

Later, found information, spend me a day, the following is my solution: 1. Declare a DLL drop [DLLIMPORT ("MSVCR70.DLL", CALLINGCONVENTION = CALLINGCONVENTION.CDECL)] unsafe public static extern int _controlfp (int n, int mask);. 2 added to the code following code means internal void ResetFPCR () {const int _EM_OVERFLOW = 0x0009001F; const int _MCW_EM = 0x000FFFFF; _controlfp (_EM_OVERFLOW, _MCW_EM);}. 3 the call completion com After the component, call the above method, such as // call COM component // then execute resetFPCR (); Note: Please see http://support.microsoft.com/default.aspx?cid=kb; -US; Q326219 &

转载请注明原文地址:https://www.9cbs.com/read-45753.html

New Post(0)