Hello i am registered here for long time but i was just following some tutorials and not activate with comments or new topics. I have a problem that i can't resolve for a couple of days. i made an application that install a global hook for keyboard but it can't hook keyboard msg in console application and browsers. I need some help to figure out the problem and i think i hope i can find this help here.
dll code is copiled with GNU GCC compiler and codeblocks as ide:
#include "main.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <cstdio>
#include <fstream>
using namespace std;
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
LRESULT CALLBACK DLL_EXPORT KeyboardProc(int code, WPARAM wParam, LPARAM lParam) {
SomeFunction("test");
LRESULT RetVal = CallNextHookEx( 0, code, wParam, lParam );
return RetVal;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
return TRUE;
}
#ifdef __cplusplus
}
#endif
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
LRESULT CALLBACK DLL_EXPORT KeyboardProc(
int code,
WPARAM wParam,
LPARAM lParam
);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
</windows.h></fstream></cstdio></windows.h>
hook set up code is compiled with MS VS 2008:
HHOOK hhandle;
HMODULE dllHandle;
HOOKPROC hookProcAddress;
dllHandle = LoadLibrary(L"hook.dll");
if (!dllHandle) cout << "LoadLibrary Call Failed, Error number: " << GetLastError() << endl;
hookProcAddress = (HOOKPROC)GetProcAddress(dllHandle, "KeyboardProc@12");
if (!hookProcAddress)cout << "GetProcAddress Call Failed, Error number: " << GetLastError() << endl;
hhandle = SetWindowsHookEx(WH_KEYBOARD, hookProcAddress, dllHandle, 0);
if (!hhandle) cout << "SetWindowsHookEx Call Failed, Error number: " << GetLastError() << endl;
i am using windows vista x32 ultimate edition
le: nobody can help me?