i have one solution file in visual studio, and i have in it two projects one for the .dll file and one other project to the .c file:
this is the .h file:
#include <windows.h>
#ifndef BHANNAN_TEST_CLASS_H_
#define BHANNAN_TEST_CLASS_H_
extern int __declspec (dllexport) Factorial(int n);
#endif
and in .c file (of the dll ):
#include "hanan.h"
#include <stdio.h>
int Factorial(int n) {
printf("in DLL %d \n" ,n);
return 0;
}
now i have a loader/tester which i try from it to load the dll to hook keystrokes in notepad, just to understand the mechanism of the hooking.
this is the code of the loader:
#include <windows.h>
#include <stdio.h>
typedef int (*functor) (int);
functor funcptr =NULL;
int main () {
HWND windowHandle;
HINSTANCE hMod;
HOOKPROC lpfn;
DWORD threadId;
HHOOK hook;
HMODULE myDLL = LoadLibraryW(L"dll123.dll");
funcptr = (functor) GetProcAddress(myDLL,"Factorial");
/// printing issues:////////////////
printf("%d \n\r" , myDLL);
printf("%d" , funcptr(33));
//////////////////////////////////////
lpfn = (HOOKPROC) funcptr;
hMod = myDLL;
windowHandle = FindWindow(L"Notepad",NULL);
threadId = GetWindowThreadProcessId(windowHandle, NULL);
hook = SetWindowsHookEx(WH_KEYBOARD,lpfn,hMod,threadId);//(WH_CBT, HookCBTProc, hInst, threadId);
/// printing issues:
printf("%d %d %d %d\n" , hook, WH_KEYBOARD , lpfn , hMod);
printf("%d %d \n",threadId , windowHandle );
getchar();
return 0;
}
i get all the printing no zeros, which means there are no nulls (assuming notepad is running), but when i do any keystroke in notepad i get an exception right away,
using visual studio 2010 and windows 7
added exception properties:
Exception Offset: 0006632c
Exception Code: c0000409
Exception Data: 00000000
Just a shot in the dark, but the function that you pass to the set hook call should look like this:
Not:
int Factorial(int n)(where are the two other params??)