This Blog Has Been Moved !

This Blog Has been moved to http://aleemkhan.wordpress.com

There is a small problem with System.Drawing.dll in VS.NET 2003. Sometimes you get an Arithmetic Exception and the program is terminated. If u get this "Arithmetic Exception" in System.Drawing.dll, then there must be some spy software or some virus installed on your system which has hooked the system and changed the FPU (FloatingPoint Unit value) for all the processes.

To Set the FPU value to dafault u can use _controlfp() function defined in "msvcrt.dll". This is a native function, to call this function in C# u will have to use .NET Runtime Interop Services. To do this add the following lines of code to your Form class

[DllImport("msvcrt.dll")]
private static extern int _controlfp(int n, int mask);
private const int _MCW_EW = 0x8001F;
private const int _EM_INVALID = 0x10;

Now call this function at the start of your form constructor

_controlfp(_MCW_EW, _EM_INVALID);

The FPU value is now set to default and you will not get any Exception in system.Drawing.dll

Comments

1 comments have been posted.
Posted @ 12:07 AM
Dear Aleem!
Nice Blog and nice effort (for others, once again). May Allah Bless You with His Blessings.

Regarding your post about System.ArithmeticException in System.Drawing.dll I have an issue. Actually I used this solution and pasted the dll ("msvcrt.dll" or initially I used "msvcr70.dll" ) in System32 folder and finally I called the _controlfp(param1,param2) from my form's contructor to initialize the Floating Point register. Initially it worked for 2 or 3 times but after that I found that the problem still persists.

Let me know if I'm doing anything wrong because I've facing this problem from couple of days and really really sick of it. It's blocked me doing any further work on Windows Forms.

regards
Your frnd
Tariq Yousaf
tariqyousaf.blogspot.com
(well it's still under construction)