Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 720
  • Last Modified:

Problem with PostThreadMessage with date time activex control (Windows XP MFC application)

Hello,

I'm getting a problem with a PostThreadMessage call within a MFC application.
The PostThreadMessage  receive handler is implemeneted in the application class(CWinAPP derived class) with ON_THREAD_MESSAGE handler as :
ON_THREAD_MESSAGE(WM_DSEXECEVENTHANDLER, ExecuteEventHandler)
The PostThreadMessage is invoked from a different thread on a basis of certain events and this scenario works except one case:

The application is build in with a datetime activex control in a dialogbox within the same application. If I open this activex control at the same time, when the PostThreadMessage happens, the receive handler doesn't get executed. Also I have checked the return value of the

PostThreadMessage call and it returns without any error message. I guess the message is getting posted in the thread queue, for some reason it is not being consumed during the activex control runtime?

Appreciate any inputs on this...

Thanks
Hari
0
pphari
Asked:
pphari
  • 2
2 Solutions
 
AndyAinscowCommented:
What is being passed - MFC objects are NOT thread safe.  You must passs a window handle instead (eg. with GetSafeHwnd() ).
0
 
mahesh1402Commented:
>>PostThreadMessage call and it returns without any error message.

For test purpose will you simply try calling the Sleep function after failure and call PostThreadMessage again, repeat until to check if PostThreadMessage succeeds ?

However PostThreadMessage is not guaranteed to work if there are any UI components in the thread.
if the thread has UI components and a MessageBox or menu is active or any other subordinate message loop the subordinate message loop will simply discard all thread messages. This is clearly stated in the documentation of PostThreadMessage. To communicate with the main GUI thread, you can use PostMessage . So otherwise use PostMessage to send a particular message to the handle of a window.

-MAHESH
0
 
mahesh1402Commented:
Following KB article may be useful
Q183116 : PRB: PostThreadMessage Messages Lost When Posted to UI Thread
http://support.microsoft.com/kb/183116

-MAHESH
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now