Below is the code snippet i used for HOOKING the WM_QUERYENDSESSION.But i never see the message box i am displaying. 1.Is there any problem with the below code 2.Also how can i discard the WM_QUERYENDSESSION at this moment so that it will not reach other applications. DLL_EXPORT void SetHook(void) { if(!bHooked) { hhook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)MsgProc, hInst, (DWORD)NULL); bHooked = TRUE; } } LRESULT CALLBACK MsgProc(int code, WPARAM wParam, LPARAM lParam) { MSG* msg; msg = (MSG*) lParam; if( code >= 0 ) { if( msg->message == WM_QUERYENDSESSION) { MessageBox( NULL , "Recieved WM_QUERYENDSESSION" , "test" , MB_OK|MB_APPLMODAL|MB_SETFOREGROUND|MB_TOPMOST ); } } return CallNextHookEx(hhook, code, wParam, lParam) ; }