I have created a DLL to inject a system hook into all processes. After a great deal of work I finally got it to compile and run without error. But when a key is pressed it doesn't seem to call the function in the DLL. My script for the DLL is as follows:
#include "stdafx.h"
#include "HookDLL.h"
#include <windows.h>
#include <iostream>
#include <stdio.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
HINSTANCE hinst;
HHOOK hhk;
LRESULT CALLBACK wireKeyboardProc(int code,WPARAM wParam,LPARAM lParam) {
printf("2");
CallNextHookEx(hhk,code,wParam,lParam);
return 0;
}
extern "C" __declspec(dllexport) void install() {
hhk = SetWindowsHookEx(WH_KEYBOARD_LL, wireKeyboardProc, hinst, 0);
printf("3");
}
extern "C" __declspec(dllexport) void uninstall() {
UnhookWindowsHookEx(hhk);
}
BEGIN_MESSAGE_MAP(CHookDLLApp, CWinApp)
END_MESSAGE_MAP()
CHookDLLApp::CHookDLLApp()
{
}
CHookDLLApp theApp;
BOOL CHookDLLApp::InitInstance()
{
CWinApp::InitInstance();
return TRUE;
}
The DllMain was commented out because it generated an error saying it was a duplicate.
The contents of the cpp file for the main file:
#include <windows.h>
#include <stdio.h>
#include <cstdlib>
#include <string>
int main(int argv[])
{
HINSTANCE hinst = LoadLibrary("HookDLL.dll");
if (hinst == NULL)
{
printf("null hinst");
}
typedef void (*Install)();
typedef void (*Uninstall)();
Install install = (Install) GetProcAddress(hinst, "install");
Uninstall uninstall = (Uninstall) GetProcAddress(hinst, "uninstall");
char ch;
install();
scanf(&ch);
uninstall();
return 0;
}
I placed a break point in the HOOKPROC and the debugger will not stop there. Any ideas or suggestions would be great.