PostMessage issues/questions
-
Hi I re-wrote my IPC methodology in the following manner Since I am creating the child process GUI I have the option of inheritable handles. One of those is a event which I signal From the console app to the MFC application The event lives in a worker thread which basically has 2 api's WaitForSingleMessage and once signaled a PostMessage. The m_hWnd is the CMainFrame main window I create in the main thread CWinApp Thing is like the SendMessage which I was doing from process to process I now have intermittent errors with this too I tried AfxGetMainWnd()->PostMessage seeing if maybe there was something wrong with the HWND First off is there any problem using a m_hWnd created in the main thread in worker thread to send a message I have read about thread maps of handles I am not sure if it relates to my scenario Thanks
-
Hi I re-wrote my IPC methodology in the following manner Since I am creating the child process GUI I have the option of inheritable handles. One of those is a event which I signal From the console app to the MFC application The event lives in a worker thread which basically has 2 api's WaitForSingleMessage and once signaled a PostMessage. The m_hWnd is the CMainFrame main window I create in the main thread CWinApp Thing is like the SendMessage which I was doing from process to process I now have intermittent errors with this too I tried AfxGetMainWnd()->PostMessage seeing if maybe there was something wrong with the HWND First off is there any problem using a m_hWnd created in the main thread in worker thread to send a message I have read about thread maps of handles I am not sure if it relates to my scenario Thanks
ForNow wrote:
I tried AfxGetMainWnd()->PostMessage seeing if maybe there was something wrong with the HWND First off is there any problem using a m_hWnd created in the main thread in worker thread to send a message
It is not correct according to [AfxGetMainWnd](https://msdn.microsoft.com/en-us/library/waas15s1(v=vs.100).aspx): "If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call." And "yes", you can pass "a m_hWnd created in the main thread in worker thread to send a message" from a worker thread.
-
ForNow wrote:
I tried AfxGetMainWnd()->PostMessage seeing if maybe there was something wrong with the HWND First off is there any problem using a m_hWnd created in the main thread in worker thread to send a message
It is not correct according to [AfxGetMainWnd](https://msdn.microsoft.com/en-us/library/waas15s1(v=vs.100).aspx): "If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call." And "yes", you can pass "a m_hWnd created in the main thread in worker thread to send a message" from a worker thread.