Page 1 of 1

Chart drawing fails after loading other 3rd party DLL

Posted: Fri Jul 14, 2006 11:45 am
by 9641587
Hi!,

I'm getting a strange exception when trying to draw a chart after loading other 3rd party DLL with CoInitialize and LoadLibrary. The place where the chart should appear is left blank with red cross over it and following exception is thrown:

Code: Select all

System.ArithmeticException: Overflow or underflow in the arithmetic operation.
   at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
   at System.Drawing.Font.Initialize(String familyName, Single emSize, FontStyle style, GraphicsUnit unit)
   at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style)
   at Steema.TeeChart.Drawing.ChartFont.get_DrawingFont()
   at Steema.TeeChart.Drawing.Graphics3DGdiPlus.MeasureString(ChartFont f, String text)
   at Steema.TeeChart.Drawing.Graphics3D.TextHeight(String text)
   at Steema.TeeChart.Drawing.Graphics3D.get_FontHeight()
   at Steema.TeeChart.Title.Draw(Graphics3D g, Rectangle& rect)
   at Steema.TeeChart.Title.DoDraw(Graphics3D g, Rectangle& rect, Boolean CustomOnly)
   at Steema.TeeChart.Chart.DrawTitleFoot(Rectangle& rect, Boolean CustomOnly)
   at Steema.TeeChart.Chart.DrawTitlesAndLegend(Graphics g, Rectangle& tmp, Boolean BeforeSeries)
   at Steema.TeeChart.Chart.InternalDraw(Graphics g, Boolean noTools)
   at Steema.TeeChart.Chart.InternalDraw(Graphics g)
   at Steema.TeeChart.TChart.Draw(Graphics g)
   at Steema.TeeChart.TChart.OnPaint(PaintEventArgs pe)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
I know that it may be impossible to say what the exact cause for this is, but does anyone have any ideas on what might be causing this behavior?
I'm using Visual C++.NET 2003.

Thanks in advance!

Posted: Fri Jul 14, 2006 11:53 am
by narcis
Hi j-o-l,

Is the chart drawn correctly without loading this 3rd party DLL?

Thanks in advance.

Posted: Fri Jul 14, 2006 12:03 pm
by 9641587
narcis wrote:Hi j-o-l,

Is the chart drawn correctly without loading this 3rd party DLL?

Thanks in advance.
Yes, everything works fine before I execute CoInitialize(NULL) and LoadLibrary(...).

Posted: Mon Jul 17, 2006 10:32 am
by narcis
Hi j-o-l,

Some time ago another customer reported something very similar, could you please have a look at that customer's message?

Thanks in advance.

Posted: Mon Jul 17, 2006 10:56 am
by 9641587
Hi,

I tried setting all the titles invisible and now charts seem to be working again. So the problem seems to be related to fonts somehow.
I tried unloading that other DLL before drawing any charts but I still got the same exception...

narcis wrote:Hi j-o-l,

Some time ago another customer reported something very similar, could you please have a look at that customer's message?

Thanks in advance.

Posted: Tue Jul 18, 2006 11:36 am
by narcis
Hi j-o-l,

The fonts work fine in TeeChart and that it's the other dll that seems to be making a mess of them. If you take out all references to TChart but use the other dll, can you use fonts correctly?

Posted: Tue Jul 18, 2006 11:51 am
by 9641587
Hi,

I'm able to use labels etc. components normally after loading that DLL, that exception is thrown only when I'm trying to draw a chart with some text in it (titles etc..).

Posted: Wed Jul 19, 2006 10:58 am
by narcis
Hi j-o-l,

How about puting a panel on a form with your other dll, override the OnPaint event and use graphics.TextOut with a new font to draw a string to the canvas? You can either override the OnPaint method, which would mean deriving from the Panel class, or you can put the font creation/string drawing code in the Panel's paint event.

Posted: Tue Jul 25, 2006 10:39 am
by 9641587
Are you referring to System::Drawing::Graphics? That class doesn't have TextOut but DrawString worked when I tried that.. So GDI+ seems to be working fine (but TeeChart is using GDI to draw those texts?).
I know that that 3rd party dll I'm loading includes some Borland runtime libraries & VCL components, maybe those have something to do with the problem?

I accidentally found out that adding following lines after the dll loading charts seem to be drawing correctly again:

Code: Select all

Graphics* gr = CreateGraphics();
gr->Dispose();
try {
IntPtr hdc = gr->GetHdc();
} catch(...) {}
... but I have no idea why that seems to fix the problem.
narcis wrote:Hi j-o-l,

How about puting a panel on a form with your other dll, override the OnPaint event and use graphics.TextOut with a new font to draw a string to the canvas? You can either override the OnPaint method, which would mean deriving from the Panel class, or you can put the font creation/string drawing code in the Panel's paint event.

Posted: Wed Jul 26, 2006 10:25 am
by 9641587
Hi,

I now received a new version of that dll with less Borland dependencies and everything seems to be working now.