473,856 Members | 1,634 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 SimpleOpenGLCon trol, 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.wglCreateCo ntext(m_hDC);

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

private void myObj_ReceivedD ata(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_ReceivedD ata(ref Array buffer)
{
myGlCtrl.SetDat a((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(th is.Handle) function call. When this happens I can't
successfully MakeCurrent. When I make calls to Marshal.GetLast Win32Error()
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.SetDat a(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 3394
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 SimpleOpenGLCon trol, 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.wglCreateCo ntext(m_hDC);

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

private void myObj_ReceivedD ata(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_ReceivedD ata(ref Array buffer)
{
myGlCtrl.SetDat a((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(th is.Handle) function call. When this happens I can't
successfully MakeCurrent. When I make calls to Marshal.GetLast Win32Error()
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.SetDat a(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
1298
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 will be added to the page at runtime (through add or delete button clicks). I have created a class for the control(PersonPanel), and have created a collection class(PersonPanelCollection)to hold and store all the controls at runtime, but due to the...
1
1708
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 public properties of a custom Control neatly tied together -- rather than all over the IDE. One such set of values that will rarely be changed, so should have little priority in the IDE Properties panel, and therefore a good candidate for
7
2028
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 control graphics object in the paint event. Any help would be appreciated. Here is my code: public class as mycontrol Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nxDest As Integer, ByVal nyDest As...
0
3563
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 hidden e.g. emmedded in dll, code does not save data as an picture. How should I handle this kind of situation? How can I get data printed to file if AxWebBrowser is hidden and
2
1911
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 wrote the MFC app and the .NET control, so we can add hook functions into either module if necessary. The .NET control is hosted in the MFC app using the CWinFormsControl template.
1
3246
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' & 'Cancel'). Till this point, no problem. Initially, the TextBox is empty. The Button has a property named 'ConfirmMessage' so that the developer using this custom control can modify the question in the confirm dialog. If the user clicks 'OK', I want the...
5
19721
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 similar to how it works in a text box. For example, if I put focus on a TextBox and then switch my language on the language bar to Japanese or Chinese, several buttons appear on the language bar including Input Mode, Input Style, Conversion Mode,...
4
2119
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 required validator. I need to have a validator for my custom control, but don't know how to do this. I added a CustomValidator to the form, but in design mode, my custom
8
4328
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 FromImage call will fail for indexed bitmaps.
0
9763
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10787
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10390
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7932
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7098
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5762
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5960
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4578
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3203
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.