am trying to understand windows hooks by writing a few keyboard hooks. i have a function,
bool WriteToFile(WPARAM keyCode, char * fileName)
{
ofstream fout("filename");
if(fout.is_open())
{
if(keyCode>=0x030 && keyCode<0x039)
fout<< (keyCode - 0x030);
fout.close();
return true;
}
else fout.close();
return false;
}
That i try to call from here but it almost always fails. Why??
LRESULT CALLBACK KbHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode > 0)
{
WriteToFile(wParam,"log.txt"); //this function always fails . Why
}
else return CallNextHookEx(hCurrentHook, nCode, wParam, lParam);
}