I am trying to retrieve messages for another application with a Windows hook. I have setup a WH_GETMESSAGE hook with SetWindowsHookEx. This is done via a DLL. In my GetMsgProc function (that should be called whenever the target application receives a message) I want to take action based on the type of message. However I am having trouble with this if statement.
LRESULT CALLBACK MessageHookProcedure(int code, WPARAM wParam, LPARAM lParam){
if(((MSG*)lParam)->message == WM_COMMAND){
MessageBox(NULL,L"The hook procedure was called",L"Test Window",MB_OK);
}
return CallNextHookEx(g_MessageHook,code,wParam,lParam);
}
For some reason the MessageBox is never created. I know the application is receiving WM_COMMAND messages from Spy++. If I take out the IF statement the MessageBox is created over and over as it receives a variety of messages.