Compiler Errors Using SetWindowsHookEx in C++ Native DLL

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
 
L

Lloyd Dupont

A quick look at VS.NET hep convince me that SetWindowsHookEx is defined on
the destop but not on the PPC
 
S

SteveV

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
 
P

Paul G. Tobey [eMVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top