473,396 Members | 1,853 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,396 software developers and data experts.

Custom Control Loses Device Context

I'm using VS 2003 my project uses COM interop and the Tao Framework.

I have a custom control derived from UserControl. It implements many
functions similar to the Tao's SimpleOpenGLControl, for example I also have a
MakeCurrent() method. Inside of the overriden method for CreateParams() I
also set the CS_OWNDC bit so that my control has a private DC. During
instantiation of my control I make a call to User32.dll to GetDC(IntPtr
handle) passing this.Handle as the argument and hold that as a member
variable, m_hDC, of my class. Then using Tao I then get the Rendering
Context with a m_hRC = Wgl.wglCreateContext(m_hDC);

My application is to take data from a COM object's Connection Point.
Basically it looks like this ReceivedData(SAFEARRAY(BYTE)* buffer). Using VS
to create the event handler for me I get in C#

private void myObj_ReceivedData(ref Array buffer)
My custom control has a method called SetData(byte[] data) so inside of my
event handler the code looks like this

private void myObj_ReceivedData(ref Array buffer)
{
myGlCtrl.SetData((byte[])buffer);
}
Now here is my problem. When the event handler is triggered my control
throws out errors. When I step into SetData() I fall into a position where
I'm watching the m_hDC and it all of the sudden doesn't match the
User32.GetDC(this.Handle) function call. When this happens I can't
successfully MakeCurrent. When I make calls to Marshal.GetLastWin32Error()
I've had it return #6, "The handle is invalid." and also #170, "The requested
resource is in use." I'm not sure which handle the error is referring to but
I do know that my control's Handle is constant and did not change.

Shouldn't the device context remain the same value since it is a private DC?

I also know that my control does draw. Because as a test I was at first
using a timer on my application that randomly filled a byte[] at every 500ms.
Inside the timer1_Tick(...) event handler I made the
myGlCtrl.SetData(m_data) call and it drew fine. But when I switched my
application to the COM object as the data source things went bad.

Is there another step I need to perform when getting data from the COM object?

Any help will be greatly appreciated.
Thanks in advance,

Dennis
Nov 17 '05 #1
1 3361
It appears that my COM object's connection Point is coming in on a seperate
thread other than my UI thread.

Since this is using OpenGL that is invalid for my rendering context. There
can be only one ACTIVE rendering context per thread.

I believe I've found the solution. I had to use modify my code slightly so
that my SetData routine did no GL commands and only manipulated the data.
Then I used Invoke to get the other thread to start my Rendering on the UI
thread.

I hope this may help someone else in the future. I now I've spent to much
time with it.
Dennis

"Dennis" wrote:
I'm using VS 2003 my project uses COM interop and the Tao Framework.

I have a custom control derived from UserControl. It implements many
functions similar to the Tao's SimpleOpenGLControl, for example I also have a
MakeCurrent() method. Inside of the overriden method for CreateParams() I
also set the CS_OWNDC bit so that my control has a private DC. During
instantiation of my control I make a call to User32.dll to GetDC(IntPtr
handle) passing this.Handle as the argument and hold that as a member
variable, m_hDC, of my class. Then using Tao I then get the Rendering
Context with a m_hRC = Wgl.wglCreateContext(m_hDC);

My application is to take data from a COM object's Connection Point.
Basically it looks like this ReceivedData(SAFEARRAY(BYTE)* buffer). Using VS
to create the event handler for me I get in C#

private void myObj_ReceivedData(ref Array buffer)
My custom control has a method called SetData(byte[] data) so inside of my
event handler the code looks like this

private void myObj_ReceivedData(ref Array buffer)
{
myGlCtrl.SetData((byte[])buffer);
}
Now here is my problem. When the event handler is triggered my control
throws out errors. When I step into SetData() I fall into a position where
I'm watching the m_hDC and it all of the sudden doesn't match the
User32.GetDC(this.Handle) function call. When this happens I can't
successfully MakeCurrent. When I make calls to Marshal.GetLastWin32Error()
I've had it return #6, "The handle is invalid." and also #170, "The requested
resource is in use." I'm not sure which handle the error is referring to but
I do know that my control's Handle is constant and did not change.

Shouldn't the device context remain the same value since it is a private DC?

I also know that my control does draw. Because as a test I was at first
using a timer on my application that randomly filled a byte[] at every 500ms.
Inside the timer1_Tick(...) event handler I made the
myGlCtrl.SetData(m_data) call and it drew fine. But when I switched my
application to the COM object as the data source things went bad.

Is there another step I need to perform when getting data from the COM object?

Any help will be greatly appreciated.
Thanks in advance,

Dennis

Nov 17 '05 #2

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

Similar topics

0
by: Tom | last post by:
I am developing a page that will contain multiple instances of a Composite Custom Control that i have developed. The problem is that the user will determine at run time how many of the control...
1
by: Sky Sigal | last post by:
(PS: Cross post from microsoft.pulic.dotnet.framework.aspnet.webcontrols) I've been looking lately for a way to keep the Properties panel for Controls 'clean'... My goal is to keep similar...
7
by: Dennis | last post by:
I am trying to implement drawing on a bitmap and using bitblt to transfer it to the control graphics object in the paint event. It seems to draw on the bitmap ok but doesn't get transferred to the...
0
by: Berry W | last post by:
Hi, I'm trying to capture hidden window's data that is in IE's AxSHDocVw.AxWebBrowser ActiveX control. If Control and window are visible, code below works but if Control and it's window is...
2
by: mmacrobert | last post by:
We have an MFC application mixed with a few .NET controls. I would like to be able to render the content of a .NET control to an MFC device context - specifically a printing device context. We...
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
5
by: Blue | last post by:
We have a custom word processing type editor built with C# and .NET 2.0 and we need to support typing in languages other than English. I want to be able to use the Windows IME to enter in text...
4
by: Rick | last post by:
Hello, I built a composite web control that has a textbox and a date control. added my custom control on a webform where there are other standard controls. Each control on the form has a...
8
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.