Compiler Errors Using SetWindowsHookEx in C++ Native DLL

  • Thread starter Thread starter SteveV
  • Start date Start date
S

SteveV

I'm trying to create a native c++ dll so that I can hook keyboard
messages and forward them to my compact frame work MessageWindow.

Here's a code snippet from my dll:

VOLUMEHOOK_API bool InitHook(HWND hMsgWnd, HINSTANCE hMod)
{
ghMessageWnd = hMsgWnd;
ghHook = SetWindowsHookEx(WH_KEYBOARD_LL, &LowLevelKeyboardProc,
(HINSTANCE)hMod, 0);

return ghHook != NULL;
}

When I try to compile the project I get the following errors:

error C2065: 'SetWindowsHookEx' : undeclared identifier
error C2440: '=' : cannot convert from 'int' to 'struct HHOOK__ *'

What's really weird is that intellisense shows the function and
parameters when I use the global scope operator like so:

ghHook = ::SetWindowsHookEx(WH_KEYBOARD_LL, &LowLevelKeyboardProc,
(HINSTANCE)hMod, 0);

Unfortunately, in addition to the 2 errors above, this results in the
following additional error:

error C2039: 'SetWindowsHookEx' : is not a member of '`global
namespace''


Any idea what I might be doing wrong?

TIA
Steve
 
A quick look at VS.NET hep convince me that SetWindowsHookEx is defined on
the destop but not on the PPC
 
You're right, it's not in the docs but apparently it is exported in
coredll and some poeple on this group have had success using it.

I just don't understand why in my case intellisense shows the function
and parameters but it still get compile errors.

Steve
 
It actually is there, but you have to declare it. I've done *exactly* what
you're doing and it works on our Windows CE.NET 4.2-based devices, at least.
I got the declaration from pwinuser.h in Platform Builder. Here's how the
function is declared there:

HHOOK
WINAPI
SetWindowsHookExW(
int idHook,
HOOKPROC lpfn,
HINSTANCE hmod,
DWORD dwThreadId);
#define SetWindowsHookEx SetWindowsHookExW

Paul T.
 
Back
Top