PostMessage to a different thread's messageQueue
-
Hi, In my win32 application i open a working thread using _beginThread(...). This thread preforms a certain work and when it's done it has to notify the main application thread. I'm implementing this by having the working thread to post a message (that will be processed by the main thread) and commit suicide (_endthread()). For some reason the posted messages of the working thread are not received in the other threads message proc. Does anyone have an idea? Thanks in advance. Snir Yarom.
-
Hi, In my win32 application i open a working thread using _beginThread(...). This thread preforms a certain work and when it's done it has to notify the main application thread. I'm implementing this by having the working thread to post a message (that will be processed by the main thread) and commit suicide (_endthread()). For some reason the posted messages of the working thread are not received in the other threads message proc. Does anyone have an idea? Thanks in advance. Snir Yarom.
Maybe posting the relevant code will help. BTW why doesn't the worker thread just return?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Maybe posting the relevant code will help. BTW why doesn't the worker thread just return?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeHere's the relevant code:
void RunAuthenticate(LPVOID pThreadId); //decleration void MyClass::Authenticate(std::string userName, std::string password, int *balance, HWND hwnd) { //working thread initialization m_threadNum++; HANDLE hThrd = (HANDLE)_beginthread(RunAuthenticate, 0, &m_threadNum); } //Global function void RunAuthenticate(LPVOID pThreadId) { HWND hwnd = CComManager::GetInstance()->GetCallingWnd(pThreadId); //return the calling window hwnd long proc; DWORD hThread = ::GetWindowThreadProcessId(hwnd,(LPDWORD)&proc); if(hThread != NULL) ::PostThreadMessage((DWORD) hThread,(UINT)THREAD_FINISHED, (WPARAM)status, NULL); }
Thanks. -
Maybe posting the relevant code will help. BTW why doesn't the worker thread just return?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeMore Clarifications: The calling thread returns right after initializing the working thread. The working thread should notify the main thread asynchly when his job was done. The notification message (::PostThreadMessage(...)) isn't caught in the main thread message proc. Thanks again. Snir_ya
-
More Clarifications: The calling thread returns right after initializing the working thread. The working thread should notify the main thread asynchly when his job was done. The notification message (::PostThreadMessage(...)) isn't caught in the main thread message proc. Thanks again. Snir_ya
What is
CComManager
(is your?)? Why don't you simply pass the Main Window handle to the working thread so that the latter can post a message to?If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
What is
CComManager
(is your?)? Why don't you simply pass the Main Window handle to the working thread so that the latter can post a message to?If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeThanks for your reply. 1. Yes, CComManager is mine. In my code it returns the HWND of the (login) dialog that called the working thread. The (login) dialog was intialized by the main thread. The working thread needs to post a message to this dialog. But all the messages sent by the working thread are lost. 2. It's a win32 application. How do i get the Main window handle? Thanks again for your help. Snir_ya.
-
Thanks for your reply. 1. Yes, CComManager is mine. In my code it returns the HWND of the (login) dialog that called the working thread. The (login) dialog was intialized by the main thread. The working thread needs to post a message to this dialog. But all the messages sent by the working thread are lost. 2. It's a win32 application. How do i get the Main window handle? Thanks again for your help. Snir_ya.
Post the message to the main window. When you create the main window (i.e.e inside
InitInstance
in the wizard-generated code), you have the great opportunity to store its handle for later use. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Thanks for your reply. 1. Yes, CComManager is mine. In my code it returns the HWND of the (login) dialog that called the working thread. The (login) dialog was intialized by the main thread. The working thread needs to post a message to this dialog. But all the messages sent by the working thread are lost. 2. It's a win32 application. How do i get the Main window handle? Thanks again for your help. Snir_ya.