'System.ArithmeticException' occurred in system.drawing.dll

P

Peter

I have made an ActiveX dll containing a COM interface with Borland C++
Builder.
The dll does some low level things and does not put of any dialogs or so.
This COM dll is used in .NET and seems to work very nicely in small example
apps without much GUI stuff.

However there's a big problem.
When the app in which the com object is instanciated contains a bit more GUI
stuff following error occurs :

A first chance exception of type 'System.ArithmeticException' occurred in
system.drawing.dll
Additional information: Overflow or underflow in the arithmetic operation.

The simpelest situation where it could be reproduced was
line 1 : make instace
line 2 : create font (fnt = New Font(,))

The exception always occurs on the second line.

I'm totally out of ideas.
I have removed everything out of the com object constructor, the dll
instance basically doesn't do much anymore and still the problem occurs.
please help as I'm stuck completely now. I have little or no experience
with .NET, I just provided a working COM object that for some reason doesn't
work well under .NET ?
 
P

Peter

Btw. I have a hard time understanding why a com instance that works 'well'
influences paint (?) actions by .NET at a later stage.
 
P

Peter

I tried a solution based on these two postings and it seems to work.
I just hope the solution is a good one.

http://support.microsoft.com/default.aspx?scid=KB;EN-US;q326219&
http://groups.google.be/[email protected]&rnum=2


I ended up adding this module (based on the second link)


Module DotNetBugFix

<DllImport("msvcr70.dll", _
CallingConvention:=CallingConvention.Cdecl)> _
Function _controlfp(ByVal n As Integer, ByVal mask As Integer) _
As Integer
End Function

Public Sub InitFPCR()
' init per :
' http://support.microsoft.com/default.aspx?scid=KB;EN-US;q326219&

' Don't seem to need this

_controlfp(&H4, &H8001F)

'
End Sub

Public Sub ResetFPCR()
' reset the FPC Register (Word) to its default value,
' as expected by .Net framework
'
_controlfp(&H9001F, &HFFFFF)
'
End Sub

End Module


I added the InitFPCR function because the MS FAQ seems to suggest something
like that but it causes problems so I'm not calling it anywhere.
When I call ResetFPCR right after I create the instance of the COM object
the next line (creating the font) works without problems.

I'm not confident enough that this really deals with the issue ?
I'm also not sure if the problem cannot reappear, e.g. after one of the
functions from the COM interface is called ?
What do you think ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top