Windows programming

Moderators: None (Apply to moderate this forum)
Number of threads: 3711
Number of posts: 9173

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Hooks in C++ Posted by kike0x on 4 Oct 2003 at 2:43 PM
Some time ago, I was doing myself a windows hook with Object Pascal (Delphi) and it worked correctly, but now, I've been working on a hook that doesn't work at all. In the hook procedure, in the dynamic library
i put this little code in the header file :

extern "C" {
HOOKDLL_API LRESULT CALLBACK WndHKK(int code, WPARAM _key, LPARAM _other);
}

and in the source file i put this one :

__declspec(dllexport) LRESULT CALLBACK hookproc(int code, WPARAM _key, LPARAM _other)
{
return CallNextHookEx(_h, code, _key, _other);
}

Then, for the test program I wrote the following code :

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG m;
HHOOK hook;
HMODULE lib = LoadLibrary("HookDLL.dll");
HOOKPROC proc = (HOOKPROC)GetProcAddress(lib, "LInit"); // It returned the

if (!(hook = SetWindowsHookEx(WH_KEYBOARD, proc, lib, 0)))
{
HOOKERROR;
return 0;
}
SendMessage((HWND)hInstance, WM_KEYDOWN, 98, 0);
while (GetMessage(&m, 0, 0, 0))
{
TranslateMessage(&m);
DispatchMessage(&m);
}
UnhookWindowsHookEx(hook);
return 0;
}

And the GetProcAddress didn't gave me the value I had expected ...
Later I tried loading the library implicitly with the process, and it work
correctly creating the HOOK but when I test it debbuging from the DLL I realised
that it didn't passing through the code in the DLL. Please , help me quickly
Report
Re: Hooks in C++ Posted by madhur_ahuja on 5 Oct 2003 at 2:40 AM
hello
i dont do windows programming in C++ but in asm so i couldnt get much from you code.
did you share the data section of dll and your program which are must for system wide hooks. just a thought.


: Some time ago, I was doing myself a windows hook with Object Pascal (Delphi) and it worked correctly, but now, I've been working on a hook that doesn't work at all. In the hook procedure, in the dynamic library
: i put this little code in the header file :
:
: extern "C" {
: HOOKDLL_API LRESULT CALLBACK WndHKK(int code, WPARAM _key, LPARAM _other);
: }
:
: and in the source file i put this one :
:
: __declspec(dllexport) LRESULT CALLBACK hookproc(int code, WPARAM _key, LPARAM _other)
: {
: return CallNextHookEx(_h, code, _key, _other);
: }
:
: Then, for the test program I wrote the following code :
:
: int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
: LPSTR lpCmdLine, int nCmdShow)
: {
: MSG m;
: HHOOK hook;
: HMODULE lib = LoadLibrary("HookDLL.dll");
: HOOKPROC proc = (HOOKPROC)GetProcAddress(lib, "LInit"); // It returned the
:
: if (!(hook = SetWindowsHookEx(WH_KEYBOARD, proc, lib, 0)))
: {
: HOOKERROR;
: return 0;
: }
: SendMessage((HWND)hInstance, WM_KEYDOWN, 98, 0);
: while (GetMessage(&m, 0, 0, 0))
: {
: TranslateMessage(&m);
: DispatchMessage(&m);
: }
: UnhookWindowsHookEx(hook);
: return 0;
: }
:
: And the GetProcAddress didn't gave me the value I had expected ...
: Later I tried loading the library implicitly with the process, and it work
: correctly creating the HOOK but when I test it debbuging from the DLL I realised
: that it didn't passing through the code in the DLL. Please , help me quickly
:






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.