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

WndProc and thread contexts

Hi all,

I'm seeing cases running my application outside the debugging environment
where WndProc is running in a separate thread context from the form and
mainline. This is causing issues trying to post messages from the middleware
since the windows handle is in a different context and therefore the
PostMessage() call returns an INVALID_WINDOW_HANDLE error. Has anyone else
experienced this? Is there a way to force WndProc, the form, and mainline to
all run in the same thread context? Thanks for any help.

-Mike

Nov 21 '05 #1
3 3798
Just an update on the problem...when I create the debug version of the code
and run it (outside VS), I'm seeing WndProc and the form running in different
threads. The release version doesn't seem to do this. If I run in the VS
environment, it almost always assigns WndProc, the form, and the mainline
separate threads. Is there any way to override this in the debugger?

"mike2036" wrote:
Hi all,

I'm seeing cases running my application outside the debugging environment
where WndProc is running in a separate thread context from the form and
mainline. This is causing issues trying to post messages from the middleware
since the windows handle is in a different context and therefore the
PostMessage() call returns an INVALID_WINDOW_HANDLE error. Has anyone else
experienced this? Is there a way to force WndProc, the form, and mainline to
all run in the same thread context? Thanks for any help.

-Mike

Nov 21 '05 #2
This is causing issues trying to post messages from the middleware
since the windows handle is in a different context and therefore the
PostMessage() call returns an INVALID_WINDOW_HANDLE error.
Window handles are valid "globally" on the same desktop, and you can
call PostMessage from any thread. The only reason I can see for
PostMessage to return that error is that the handle is indeed invalid
(i.e. the window has been destroyed or the handle contains a bogus
value).

Is there a way to force WndProc, the form, and mainline to
all run in the same thread context?


"the form" is an object and as such doesn't run on any specific
thread. The methods of the object run on whatever thread they are
called on.

I'm not sure what you mean by "mainline".

WndProc should definitely ony be called from the thread the window was
created on.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #3
Hi Mattias,

Thanks for the reply. I think my problem may have something to do with the
fact that my application uses a hidden form to get messages sent to it via
WndProc, and that the window wasn't getting registered because it never went
through its 'load' event...I can see this because after I instantiate the
form, I do a Hide(), and my load event handler for the form never gets
called. If I do a Show() and then a Hide() immediately after, the window
gets 'loaded' by the Show() call, and all the thread ID are the same both
inside and outside the debugger. The windows handle is also valid. So it
looks like it was more an issue with the proper loading of the window than
separate thread IDs.

-Mike

"Mattias Sjögren" wrote:
This is causing issues trying to post messages from the middleware
since the windows handle is in a different context and therefore the
PostMessage() call returns an INVALID_WINDOW_HANDLE error.


Window handles are valid "globally" on the same desktop, and you can
call PostMessage from any thread. The only reason I can see for
PostMessage to return that error is that the handle is indeed invalid
(i.e. the window has been destroyed or the handle contains a bogus
value).

Is there a way to force WndProc, the form, and mainline to
all run in the same thread context?


"the form" is an object and as such doesn't run on any specific
thread. The methods of the object run on whatever thread they are
called on.

I'm not sure what you mean by "mainline".

WndProc should definitely ony be called from the thread the window was
created on.
Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 21 '05 #4

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

Similar topics

6
by: Beach Potato | last post by:
Hi: I've searched newsgroups and various archives, including MSDN & MFC sources, but at this point failed to locate an accurate and simple implementation of WndProc function for MSWindows window...
0
by: sshuangw | last post by:
Hello: I am encountering a very weird issue with MDI child, Overriden WndProc function and hidden form. Basically, the application has two forms, Form1(parent form), Form2(Child form),...
2
by: Ed Sutton | last post by:
How can a WndProc be created inside a component? Currently I have a WndProc in my frmMain. It looks for WM_DEVICECHANGE messages for connection and removal events for a USB/Serial device. My...
0
by: cyrille | last post by:
Hello from example from web i did a little code to avoiding columnHeader resize. this code seems to work well, but when I put a 'normal' ListView on the same Form than my overrided ListView it...
7
by: MariusI | last post by:
Are objects implicitly stored in the TLS of the currently running thread? When creating multithreaded applications i get errors when accessing data from a different thread than the thread used to...
2
by: shengmin.ruan | last post by:
when i use delegate like this: ----------------- protected override void WndProc(ref Message m) { delegate_ReplyFromDataProcess = new...
2
by: Chris Ashley | last post by:
Hi, I'm overriding WndProc to process some custom messages like so: protected override void WndProc(ref Message m) { if (m.Msg == ImageFileMsg.MSG_IF_NEW_DATA) { ProcessNewDataMessage(m);
4
by: Rob | last post by:
I've constructed a user control inherited from ListView so I can handle and respond to scrolling events (to keep 2 listviews scrolling in sync). My user control includes an Overrides of WndProc...
0
by: makifsar | last post by:
I am using a comserver to communicate remote equipments. This server gives response via WndProc. First I call READ function to start communication and remote equipment gives response this via...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.