working prob

i made one program in c for keyboard hooking but its not working i made first one dll and after made one exe which load dll it is sample code

/*THIS IS DLL CODE Replace "dll.h" with the name of your header */

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include "key.h"

HINSTANCE hinstance;
HHOOK hook;
LRESULT _declspec (dllexport)_stdcall KeyboardProc(int code,WPARAM wparam,LPARAM lparam)
{
if (code < 0)
{
return CallNextHookEx(hook,code,wparam,lparam);
}
if ((code == HC_ACTION)&&((wparam == WM_SYSKEYDOWN)||(wparam == WM_KEYDOWN)))
{
MessageBox(NULL,"TAB PRESS","WINDOWS",MB_OK);
}
return CallNextHookEx(hook,code,wparam,lparam);
}
BOOL _stdcall DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
hinstance = hInst;
return TRUE;
}
BOOL _declspec (dllexport) installhook()
{
hook = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,hinstance,0);
}

and its header file key.h

#ifndef _DLL_H_
#define _DLL_H_

#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */


DLLIMPORT BOOL installhook();



#endif /* _DLL_H_ */


and after it my exe code

#include<windows.h>
#include<stdio.h>

int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprvinstance,LPSTR cmdt,int cmdl)
{
HINSTANCE h;
h = LoadLibrary("key.dll");
BOOL (*p)();
p = GetProcAddress(h,"installhook");
(*p)();
}

give me right direction thx i only want when i press key my messagebox displyed

Last edited on
Topic archived. No new replies allowed.