1

Topic: Win7: PostThreadMessage does not send the message?

Is Win32 application which loads DLL (in-proc) in it it is transferred HWND and in DLL such code: HWND hwnd = get_hwnd (); if (hwnd! = NULL) {DWORD process_id = 0; DWORD thread_id =:: GetWindowThreadProcessId (hwnd, &process_id);//in debugging thread_id == Main Thread the main Win32 applications if (thread_id! = NULL) {BOOL res =:: PostThreadMessage (thread_id, WM_CLOSE, 0, 0);//res == 1 if (! res) {//here does not come};};}; Spy ++ does not see the new message, in WNDPROC Win32 applications comes nothing. In what there can be a problem?

2

Re: Win7: PostThreadMessage does not send the message?

Hello, turbocode, you wrote: T> Is Win32 application which loads DLL (in-proc) in it it is transferred HWND and in DLL such code: T> T> HWND hwnd = get_hwnd (); T> if (hwnd! = NULL) T> {T> DWORD process_id = 0; T> DWORD thread_id =:: GetWindowThreadProcessId (hwnd, &process_id);//in debugging thread_id == Main Thread the main Win32 applications T> if (thread_id! = NULL) T> {T> BOOL res =:: PostThreadMessage (thread_id, WM_CLOSE, 0, 0);//res == 1 T> if (! res) T> {T>//here does not come T>}; T>}; T>}; T> T> Spy ++ does not see the new message, in WNDPROC Win32 applications comes nothing. T> in what there can be a problem? Messages sent by PostThreadMessage are not associated with a window. As a general rule, messages that are not associated with a window cannot be dispatched by the DispatchMessage function. In other words, they do not get to window procedure, they should be processed at once in a cycle of messages. And why not to make simply PostMessage?

3

Re: Win7: PostThreadMessage does not send the message?

VTT> Messages sent by PostThreadMessage are not associated with a window. As a general rule, messages that are not associated with a window cannot be dispatched by the DispatchMessage function. VTT> In other words, they do not get to window procedure, they should be processed at once in a cycle of messages. And how it dares? VTT> and why not to make simply PostMessage? DLL can work not mandatory in core GUI a flow.

4

Re: Win7: PostThreadMessage does not send the message?

Hello, turbocode, you wrote: VTT>> Messages sent by PostThreadMessage are not associated with a window. As a general rule, messages that are not associated with a window cannot be dispatched by the DispatchMessage function. VTT>> In other words, they do not get to window procedure, they should be processed at once in a cycle of messages. T> and how it dares? Handling of such messages in a cycle of messages. VTT>> and why not to make simply PostMessage? T> DLL can work not mandatory in core GUI a flow. And for PostMessage it and not a problem.

5

Re: Win7: PostThreadMessage does not send the message?

Hello, turbocode, you wrote: T> Is Win32 application which loads DLL (in-proc) in it it is transferred HWND and in DLL such code: If is hWnd why not to send WM_CLOSE or to it, if it top level, or it nop-level to the ancestor? What for to a flow to send? Well and if it is necessary nevertheless for a flow - as already told, to catch in a loop of messages.

6

Re: Win7: PostThreadMessage does not send the message?

VTT> And for PostMessage it and not a problem. Made through PostMessage now Spy ++ catches, and Win32 to application WM_CLOSE does not come. Where it could be lost?

7

Re: Win7: PostThreadMessage does not send the message?

Hello, turbocode, you wrote: T> Is Win32 application which loads DLL (in-proc) in it it is transferred HWND and in DLL such code: T> T> HWND hwnd = get_hwnd (); T> if (hwnd! = NULL) T> {T> DWORD process_id = 0; T> DWORD thread_id =:: GetWindowThreadProcessId (hwnd, &process_id);//in debugging thread_id == Main Thread the main Win32 applications T> if (thread_id! = NULL) T> {T> BOOL res =:: PostThreadMessage (thread_id, WM_CLOSE, 0, 0);//res == 1 T> if (! res) T> {T>//here does not come T>}; T>}; T>}; T> T> Spy ++ does not see the new message, in WNDPROC Win32 applications comes nothing. T> in what there can be a problem? How here already noted, if at you already is hwnd why it not to send WM_CLOSE directly?  says that for PostThreadMessage it is necessary to create message queue pens and to catch messages too pens through PeekMessage + GetMessage. The thread to which the message is posted must have created a message queue, or else the call to PostThreadMessage fails. Use the following method to handle this situation. Create an event object, then create the thread. Use the WaitForSingleObject function to wait for the event to be set to the signaled state before calling PostThreadMessage. In the thread to which the message will be posted, call PeekMessage as shown here to force the system to create the message queue: PeekMessage (&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE) Set the event, to indicate that the thread is ready to receive posted messages. The thread to which the message is posted retrieves the message by calling the GetMessage or PeekMessage function. The hwnd member of the returned MSG structure is NULL. https://msdn.microsoft.com/en-us/librar … p/ms644946 (v=vs.85).aspx