System.Argument.Exception: hdc

A

Andreas

Hi NG,

i encountered a problem during developing some activex control with c#.
I read an article that it is possible to expose windows forms as
activex controls. So I tried it and it worked really great!
Here is the link to the article:
http://www.codeproject.com/cs/miscctrl/exposingdotnetcontrols.asp

Testing the newly created control with the Testcontainer for ActiveX
Controls showed no problems.

Now I inserted my activex control into Authorware 7.0 everything is
fine the control works, but if I click at the "pause"-Button I get an
exception:

System.ArgumentException: hdc
at
System.Windows.Forms.DibGraphicsBufferManager.CreateCompatibleDIB(IntPtr
hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits)
at System.Windows.Forms.DibGraphicsBufferManager.CreateBuffer(IntPtr
src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
at
System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(Graphics
targetGraphics, IntPtr targetDC, Rectangle targetBounds)
at System.Windows.Forms.DibGraphicsBufferManager.AllocBuffer(IntPtr
target, Rectangle targetBounds)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Label.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)

Unfortunately I dont understand this exception. I dont now what the
"hdc" argument is and why this exception occurs.

Maybe anyone can help or give some suggestions?

Thanks in advance.

kind regards

Andreas Heinecke
 
D

Dmytro Lapshyn [MVP]

Hi Andres,

HDC is a handle to a device context. It is a GDI concept - you need an HDC
before you can draw anything.
Now that you receive this error, the host application appears to pass an
invalid HDC to your control when in the "pause" mode.
Judging by the stack trace, you can try to override the Label's OnWndProc
method, watch out for WM_PAINT messages and if the passed PAINTSTRUCT
contains an invalid HDC, just pretend you've handled the message.
 
A

Andreas

Hi Dmytro,

first of all thanks for your answer. But the problem still remains. So
here is what I've done. You said I should try to override OnWndProc but
I cann't find this method I've only found a method namend WndProc, but
I think this method does the same like OnWndProc. So I have overridden
this WndProc-Method an put a try-catch around the invokation of the
base.WndProc(ref m);
The problem is that my catch block never caught the exception, but the
exception is thrown and the program still breaks. I ran out of ideas
how to solve this.

I don't know how to get this exception caught.

Does anyone got some ideas? This problem should'nt be as big as it
seems to be.

Any help is much appreciated!

regards

Andreas Heinecke
 
D

Dmytro Lapshyn [MVP]

Andreas,

Instead of using try...catch, just check the message before calling
base.WndProc and if the message is WM_PAINT and the HDC in the passed
PAINTSTRUCT (refer to MSDN how to extract it from WParam and LParam) is 0 or
null, just don't call the base class but pretend you have processed the
message.
 

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