Great tutorial, well written!
Great tutorial, well written!
Why "KeyboardProc@12" and not "KeyboardProc" ?
TY
Gratz on your nice article Kekke, I'll talk to ya soon
Sokz
But, how to communicate with your program telling that a key was pressed?
amazing tutorial, big gratz, I 'm waiting for next
Normally in std calls windows symbols require the "@" and the amount of bytes the parameters take (so imagine you have one byte param and 2 int params, that gives you 9, thus FunctionName@9)Originally Posted by Bruno
[align=center]\"12:16 You lose your virginity due to an attack by Michael Jackson.\" RIP Jacko.
Join TProgramming secure chat room!
http://www.afternet.org/afternet_sta...=GUSHH&small=1[/align]
This won't work. Windows applications usually have several threads. You need to hook thread that has created main window. With this method you don't know what thread you have found. You know only that thread is connected with your process id. Finding right thread is simpler than you think. You used GetWindowThreadProcessId() function and you hasn't looked at msdn?
That's right thread .Return Value
DWORD
The return value is the identifier of the thread that created the window.
Now all should be like that.
[code=cpp]
#include <windows.h>
int main(int argc, char *argv[])
{
DWORD dwThreadId = 0;
DWORD dwProcessId = 0;
HWND hTibiaWnd = 0;
HINSTANCE hDll = 0;
HOOKPROC KeyboardProc = 0;
HHOOK hHook = 0;
hTibiaWnd = FindWindow(0, "Tibia");
if (!hTibiaWnd)
{
// Do something
return 0;
}
dwThreadId = GetWindowThreadProcessId(hTibiaWnd, &dwProcessId);
if (!dwThreadId)
{
// Do something
return 0;
}
hDll = LoadLibrary("Keyboardhooktest.dll");
if (!hDll)
{
// Do something
return 0;
}
KeyboardProc = reinterpret_cast<HOOKPROC>(GetProcAddress(hDll, "KeyboardProc@12"));
if (!KeyboardProc)
{
// Do something
return 0;
}
hHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hDll, dwThreadId);
if (!hHook)
{
// Do something
return 0;
}
system("pause");
UnhookWindowsHookEx(hHook);
FreeLibrary(hDll);
return 0;
}
[/code]
This is simpler, faster and wil work .
If somebody has problem with "KeyboardProc@12" try "_KeyboardProc@12". Anyway look at exports library file. There you will find name of your function.