Hello all
i tried to create a system wide hook (CBT) so that i can monitor processes and system events. in the very beginning i am stuck!
I cant get the name of the process! i dont know why i am getting this!
I have also tried using:
Code:
if (IsWindowUnicode((HWND) wparam))
{
CBTHOOKCREATEW = (CBT_CREATEWNDW*) lparam;
CBTHOOKCREATESTRW = (CREATESTRUCTW*) lparam;
}
which failed again !
Here is the actual code
Code:
LRESULT CALLBACK HookProcedure(int nCode, WPARAM wparam, LPARAM lparam)
{
if (nCode < 0) return CallNextHookEx(hookID, nCode, wparam, lparam);
std::ofstream outfile;
CBT_CREATEWND *CBTHOOKCREATE;
RECT *CBTRECTPTR;
RECT CBTRECT;
wstring Message;
CBTHOOKCREATE = (CBT_CREATEWND*) lparam;
outfile.open(("d:\\test.txt"), std::ios_base::app);
if (nCode >= 0) {
switch (nCode)
{
case HCBT_CREATEWND:
outfile << CBTHOOKCREATE->lpcs->lpszName << " Created! " << endl;
break;
case HCBT_DESTROYWND:
outfile << "Destroyed!" << endl;
break;
default:
break;
}
}
outfile.close();
return 0;
}
What am i doing wrong or missing here?
Thanks in advance