|
-
May 9th, 2012, 01:06 AM
#1
working problem
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
thx
-
May 9th, 2012, 01:17 AM
#2
Re: working problem
 Originally Posted by raj874
give me right direction thx i only want when i press key my messagebox displyed
Did you debug your code?
Did LoadLibrary succeed or fail?
Did GetProcAddress succeed or fail?
Victor Nijegorodov
-
May 9th, 2012, 07:18 AM
#3
Re: working problem
Actully i didnt debug it but i checked it when i display the messagebox in installhook function in dll like it its works
BOOL _declspec (dllexport) installhook()
{
hook = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,(HINSTANCE)hinstance,0);
MessageBox(NULL,"ITS WORKS","WINDOWS",MB_OK);
if (hook == NULL)
{
MessageBox(NULL,"HOOK NOT WORK","WINDOWS",MB_OK);
}
here i put one messagebox function and when i clicked on y exe that messagebox displayed mean getprocaddress works
-
May 9th, 2012, 07:21 AM
#4
Re: working problem
and also loadlibrary works fine sorry for double post this small matter
-
May 9th, 2012, 08:08 AM
#5
Re: working problem
Then try to debug your dll code!
Victor Nijegorodov
-
May 14th, 2012, 08:10 AM
#6
Re: working problem
thx i solved problem
-
May 14th, 2012, 08:14 AM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|