PostThreadMessage and PeekMessage

I've written the code using VC++5.0 in WinNT as follow:

...
void main() {
...
   ft = (HANDLE) _beginthreadex(NULL, sz, POne, 0, 0,(unsigned int*) &dft);
   r = PostThreadMessage(dft, WM_NULL, 0,0);
   Sleep(5000);
...
}

void POne() {
...
   MG msg;
   for(;;) {
      if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      (
         printf("Message Received!\n");
         break;
      }
      WaitMessage();
   }
...
}

In running the above code, the 'Message Received' does not prompt. But it work on Win95 successfully. I've no idea about this problem. Does any suggestion or advice for me?
Thank you for your attention.

Regards,
Michael

mikehuiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mikehuiAuthor Commented:
Edited text of question.
0
nietodCommented:
What messages should it be geting?  probably none.   You might try using AttachThreadInput() so that it gets some of the input messages that would be going to the main thread.

What is it that you are trying to do?
0
PinTailCommented:
Have you vaildated the return from _beginthreadex, and PostThreadMessage.

Also, you ought to Sleep in between the call to _beginthreadex and the call to PostThreadMessage, this gives the thread a chance to create it's thread message queue, which it will do upon the first call to PeekMessage.

A Sleep(1) is sufficient, however a better solution is to have a mutex, or some other synchronization object.  Have the thread signal the object after it's first call to PeekMessage(), this then allows your creating thread ( main() ) to know when the thread has activated the queue.

Remember that Win9X is still not a true pre-emptive multi-threaded environment.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mikehuiAuthor Commented:
Does any time interval required in a sequence of  PostThreadMessage function call?
0
PinTailCommented:
Do you mean 'Is there a time interval required between calls to PostThreadMessage'.

No, the Threads Message Queue will continue to accept messages as fast as you can post them, however, you should check the return from PostThreadMessage, since it can sometimes fail - for reasons unclear -
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.