tags:

views:

49

answers:

2

I've managed to get input hooks working, but now I'm kinda lost with putting them into a library.

I have a simple header with INPUTHOOK_EXPORTS defined in the IDE, so the dll exports (Visual Studio).

#pragma once

#ifdef INPUTHOOK_EXPORTS
    #define INPUTHOOK_API __declspec(dllexport)
#else
    #define INPUTHOOK_API __declspec(dllimport)
#endif

INPUTHOOK_API void InstallInputHook();
INPUTHOOK_API void RemoveInputHook();

and of course:

The cpp file

The thing is, when I try to compile this library, I get two unresolved externals, one for SetWindowsHookEx and for UnhookWindowsHookEx respectively. Why these two functions are not available, while others are and without any problem? As far as I see, I do have the includes right.

Thank you

A: 

From MSDN topic LowLevelKeyboardProc:

This hook is called in the context of the thread that installed it. The call is made by sending a message to the thread that installed the hook. Therefore, the thread that installed the hook must have a message loop.

Alex Farber
Global hook (the ...`_LL`) is supposed to run without it, because the callback is called directly. That should not be the problem, since this very code worked before I moved it to dll.
Mikulas Dite
LowLevelKeyboardProc is callback function for WH_KEYBOARD_LL hook. You need to use message loop.http://msdn.microsoft.com/en-us/library/ms644985%28VS.85%29.aspx But your question is changed: now you ask about unresolved externals.Why?
Alex Farber
`WH_KEYBOARD_LL` does not need the loop, that is the part I actually tried and it worked great, without any problem. The msnd says different for some reason, but check out comments below the main article. | The problem was moving the code into library, where for some reason hook functions don't work and pops out unresolved externals.
Mikulas Dite
A: 

SetWindowsHookEx is a macro that should turn into SetWindowsHookExA' for ascii orSetWindowsHookExWfor wchar. Similary forUnhookWindowsHookEx` .
The error reported should be specific to which function is missing - A or W - which seems to indicate for some reason the macro is not in place.

You seem to be missing winuser.h in the cpp, however this or an equivalent may be in the pre-compiled stdafx.h header.

You need to include user32.lib while building (linking) your library (normally in the default included libs).

Greg Domjan