Solution to System. ArithmeticException after com component is used in. Net

Source: Internet
Author: User

A.. Net Program, which involves calling com components. After the call, if some small test programs continue to run, everything is normal, but when the form program with GUI continues to run, the following exceptions always occur:
Exception: System. ArithmeticException
Message: overflow or underflow occurs in arithmetic operations.
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

It took me a day to solve the problem by looking for information everywhere. The following is my solution:
1. Declare a DLL for use
[DllImport ("msvcr70.dll", CallingConvention = CallingConvention. Cdecl)]
Unsafe public static extern int _ controlfp (int n, int mask );
2. Add the following code methods to the Code:
Internal void ResetFPCR ()
{
Const int _ EM_OVERFLOW = 0x0009001F;
Const int _ MCW_EM = 0x000FFFFF;
_ Controlfp (_ EM_OVERFLOW, _ MCW_EM );
}
3. After calling the com component, call the preceding method, for example:
// Call the com component here
 
// Then execute the Reset method
ResetFPCR ();
 
Note: For details, please see http://support.microsoft.com/default.aspx? Scid = KB; EN-US; q326219 &

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.