|
-
September 6th, 2007, 10:38 PM
#1
[Quiz] What will happen if SendMessage to self?
This is an interesting thing (what i never thought of yet...) and I wonder how you people think it will happen.
We normally won't sendmessage to ourself, but what if we do that?
Here are the sample example:
Code:
LRESULT CDlgExeDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch (message)
{
case WM_MYTEST:
{
if (! SendMessage(WM_MYTEST)) {
ASSERT(0);
};
int i = 0;
}
.....
Because SendMessage is a synchronous function, so THEORETICALLY it will casue an infinite loop!
But is this true?
How do you people think?
-
September 7th, 2007, 12:04 AM
#2
Re: [Quiz] What will happen if SendMessage to self?
 Originally Posted by myron
...Because SendMessage is a synchronous function, so THEORETICALLY it will casue an infinite loop!
Yes it will, and then - stack overlow...
Did you try?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
September 7th, 2007, 12:11 AM
#3
Re: [Quiz] What will happen if SendMessage to self?
m. but actually (usiang VC6)
it just runs!
(After a certain number of stack-record repetition...)
A very interesting things...
Says, what if we repalce WM_MYTEST with WM_CREATE?
The dialog/app still shows up!
What a magic.
-
September 7th, 2007, 08:59 AM
#4
Re: [Quiz] What will happen if SendMessage to self?
 Originally Posted by myron
We normally won't sendmessage to ourself, but what if we do that?
We normally don't send messages recursively to ourself (i.e. send WM_MYMESSAGE inside a WM_MYMESSAGE handler), but other than that its very normal to send messages to ourself.
-
September 7th, 2007, 10:17 AM
#5
Re: [Quiz] What will happen if SendMessage to self?
Well, there is a trcik here.
Sendmessage is synchronous function, so "theoretically" this will cause system hang out... since the sendmessage won't return back... (in single thread condition of course)
...
case WM_MYTEST:
{
if (! SendMessage(WM_SOMEOTHERMSG)) {
ASSERT(0);
};
...
-
September 7th, 2007, 10:37 AM
#6
Re: [Quiz] What will happen if SendMessage to self?
it's the first sign of madness
-
September 7th, 2007, 10:46 AM
#7
Re: [Quiz] What will happen if SendMessage to self?
 Originally Posted by myron
Well, there is a trcik here.
Sendmessage is synchronous function, so "theoretically" this will cause system hang out... since the sendmessage won't return back... (in single thread condition of course)
Unless I'm mistaken it won't necesarily hang...first execution is in the case WM_MYTEST code, then when you call SendMessage(WM_SOMETHINGELSE), execution goes to the WM_SOMETHINGELSE handler. When that handler completes, execution returns to the WM_MYTEST handler, after the SendMessage call.
Now, if we're talking about Windows messages, not user defined messages, it may or may not cause problems, depending on the message & what Windows does with it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|