473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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 ?
Jul 21 '05 #1
2 2600
Btw. I have a hard time understanding why a com instance that works 'well'
influences paint (?) actions by .NET at a later stage.

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 up 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 ?

Jul 21 '05 #2
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...EN-US;q326219&
http://groups.google.be/groups?q=Sys...gle.com&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...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 ?
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
0
by: Brian Daoust | last post by:
Hello everyone! I just installed Visual Studio .NET (2002) and just getting to learn it. I added a data form using the wizard - and it was working fine. Now, when I run it with F5 - I am...
1
by: gregory_may | last post by:
This code seems to "work" but I get the following errors: An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll then this one: An unhandled...
1
by: Ronald | last post by:
I just wrote some code on a dev machine, Imports System.Xml Imports System.Xml.XPath Imports System.Xml.Xsl Imports System.IO Imports System.Data.SqlClient Public Class ClassXMLtoHTML Dim...
11
by: Andreas Wirén | last post by:
Hi I'm a C# .NET newbie doing a minor school project but I'm getting a strange error message. 'System.NullReferenceException' occurred in system.windows.forms.dll Additional information: Object...
6
by: tom k. | last post by:
H I have XP and can't run any of my Visual Basic .net projects. I get this error every time I try to run one: An unhandled exception of type 'System.ArithmeticException' occurred in...
3
by: mfc2004 | last post by:
Hi, I have a pc with windows XP SP1, net Framworks 1.1 and visual studio net 2003 When I first installed Visual Studio 2003, I noticed I was getting th follow error when showing a form A first...
2
by: | last post by:
Hi, I'm using Windows XP SP1 with Visual Studio 2003. I add a blank form to a project, then I add a default control of any type (label, button, etc) to that form. When I build and run the...
1
by: chintu rana via DotNetMonster.com | last post by:
An unhandled exception of type 'System.ArithmeticException' occurred in system.drawing.dll Additional information: Overflow or underflow in the arithmetic operation. if i run vb.net...
0
by: Nikhil Khade | last post by:
Hello, After around 3 months, I reopened a old VB.NET solutions which used to work (and build) without any errors. Just to test it again, I build it again and it completed, without any errors,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.