Explanation on this bug fix code

ajeeshco

Well-known member
Joined
Sep 19, 2006
Messages
257
Location
Cochin, India
Programming Experience
3-5
Hi,
The following snippet of code is used in an application which was developed in vs2003 and comment is given as bug fix for framework.
VB.NET:
Imports System
Imports System.Runtime.InteropServices
	Public Class WinAPI
		Public Const UDEF_RESTORE AS integer = &H9999 
		Public Const WM_QUERYENDSESSION As Integer = &H11 
			
		const _RC_NEAR As Integer      = &H00000000
		const _PC_53 As Integer        = &H00010000
		const _EM_INVALID As Integer   = &H00000010
		const _EM_UNDERFLOW As Integer = &H00000002
		const _EM_ZERODIVIDE As Integer= &H00000008
		const _EM_OVERFLOW As Integer  = &H00000004
		const _EM_INEXACT As Integer   = &H00000001
		const _EM_DENORMAL As Integer  = &H00080000
		Const _CW_DEFAULT As Integer   = ( _RC_NEAR + _PC_53 +  _EM_INVALID + _EM_ZERODIVIDE + _EM_OVERFLOW + _EM_UNDERFLOW +  _EM_INEXACT + _EM_DENORMAL)
		
		Public Sub New()
		End Sub
		
		<DllImportAttribute("user32.dll")> _
		Public Shared Function SendMessage(hWnd As IntPtr,Msg As Integer,wParam As Integer,lParam As Integer) As Integer
			
		End Function
		
		<DllImportAttribute("msvcr71.dll")> _
		Private Shared Function _controlfp(n As Integer,mask As Integer) As Integer
			
		End Function
		
		Public Shared Sub ResetFPU			
    		_controlfp(_CW_DEFAULT ,&Hfffff)
		End Sub

	End Class

Most of you might have used this piece of code. Is this still needed for the bug fix? I'm using visual studio 2003 with latest service packs.

Thanks in Advance
 
KB says it applies only to .Net 1.0.
 
"return the floating-point register to its default state" in case unmanaged code had put it out of default state.
 
KB says it applies only to .Net 1.0.

But JohnH, I could reproduce the same error in .NET 1.1 also. I followed the steps given in this link http://support.microsoft.com/default.aspx?scid=KB;EN-US;q326219 to reproduce this behaviour and instead of msvcr70.dll I used msvcr71.dll.
The code I tried is given below
VB.NET:
    <DllImport("msvcr71.dll", CallingConvention:=CallingConvention.Cdecl)> _
    Public Shared Function _controlfp(ByVal n As Integer, ByVal mask As Integer) As Integer
    End Function

    <STAThread()> _
    Shared Sub Main()
        Const _EM_OVERFLOW As Integer = &H4
        Const _MCW_EM As Integer = &H8001F
        _controlfp(_EM_OVERFLOW, _MCW_EM)
        Application.Run(New Form1)
    End Sub
 
Maybe it was some widespread buggy software that caused it in 2003, and that this "floating-point register" thing isn't supposed to be left out of its default state, in which case that code is just to prove the point and something that would not happen normally and not something anybody is supposed to be guarding themselves from?
 
Back
Top