I am attempting to install a WH_JOURNALRECORD
with SetWindowsHookEx
:
#include <iostream>
#include <Windows.h>
LRESULT CALLBACK WndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
std::cout << "Hook called" << std::endl;
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
int main()
{
HHOOK hook = SetWindowsHookEx(WH_JOURNALRECORD, WndProc, 0, 0);
if (hook != NULL)
{
std::cout << "Hooked WH_JOURNALRECORD" << std::endl;
}
else
{
DWORD dw = GetLastError();
std::cout << "Failed to install hook:" << "(Error: " << dw << ")" << std::endl;
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
My application is signed with a certificate and ran under C:\Program Files
as Administrator, as is required for JournalRecord
hooks (/uiAccess=true
). The application launches and the hook is installed successfully, however I never receive any output from my WndProc
function. I can move my cursor, however I cannot click or type anything until I press ctrl+alt+del
or another key combo that forces Windows to uninstall the JournalRecord
hook.
According to the documentation, this type of hook is a global hook and can run within the same application context (ie, no DLL is required as is the case for other types of hooks). Despite being a console application, I have added a message loop so I don't believe that is the issue.
If anyone knows what I am doing wrong, or how I can solve this issue, any help is appreciated.