我定义的全局钩子,安装函数如下:
DllExport void WINAPI InstallLaunchEv()
{
Hook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)LauncherHook, theApp.m_hInstance,0);
}
钩子函数如下:
LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LPARAM lParam)
{
// By returning a non-zero value from the hook procedure, the
// message does not get passed to the target window
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;
BOOL bControlKeyDown = 0; switch (nCode)
{
case HC_ACTION:
{
// Check to see if the CTRL key is pressed
bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);
// Disable CTRL+ESC
if (pkbhs->vkCode == VK_ESCAPE && bControlKeyDown)
return 1; // Disable ALT+TAB
if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN)
return 1; // Disable ALT+ESC
if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN)
return 1; break;
} default:
break;
}
return CallNextHookEx (Hook, nCode, wParam, lParam);
}
编译出现一下问题:
error C2065: 'WH_KEYBOARD_LL' : undeclared identifier
error C2065: 'KBDLLHOOKSTRUCT' : undeclared identifier
error C2065: 'pkbhs' : undeclared identifier
error C2059: syntax error : ')'
error C2227: left of '->vkCode' must point to class/struct/union
error C2227: left of '->vkCode' must point to class/struct/union
error C2227: left of '->flags' must point to class/struct/union
error C2065: 'LLKHF_ALTDOWN' : undeclared identifier
error C2227: left of '->vkCode' must point to class/struct/union
error C2227: left of '->flags' must point to class/struct/union
Error executing cl.exe.LaunchDLL.dll - 10 error(s), 0 warning(s)
DllExport void WINAPI InstallLaunchEv()
{
Hook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)LauncherHook, theApp.m_hInstance,0);
}
钩子函数如下:
LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LPARAM lParam)
{
// By returning a non-zero value from the hook procedure, the
// message does not get passed to the target window
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;
BOOL bControlKeyDown = 0; switch (nCode)
{
case HC_ACTION:
{
// Check to see if the CTRL key is pressed
bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> ((sizeof(SHORT) * 8) - 1);
// Disable CTRL+ESC
if (pkbhs->vkCode == VK_ESCAPE && bControlKeyDown)
return 1; // Disable ALT+TAB
if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN)
return 1; // Disable ALT+ESC
if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN)
return 1; break;
} default:
break;
}
return CallNextHookEx (Hook, nCode, wParam, lParam);
}
编译出现一下问题:
error C2065: 'WH_KEYBOARD_LL' : undeclared identifier
error C2065: 'KBDLLHOOKSTRUCT' : undeclared identifier
error C2065: 'pkbhs' : undeclared identifier
error C2059: syntax error : ')'
error C2227: left of '->vkCode' must point to class/struct/union
error C2227: left of '->vkCode' must point to class/struct/union
error C2227: left of '->flags' must point to class/struct/union
error C2065: 'LLKHF_ALTDOWN' : undeclared identifier
error C2227: left of '->vkCode' must point to class/struct/union
error C2227: left of '->flags' must point to class/struct/union
Error executing cl.exe.LaunchDLL.dll - 10 error(s), 0 warning(s)
解决方案 »
- IEC62056规约报文如何解析,可否给出实例?请各位高手指点。
- 奇怪问题:debug模式提示_CrtIsValidHeapPointer(pUserData)错误
- 控件应用的问题,很重要也很容易被忽略,您遇到过吗??
- 鼠标移动触发事件的问题?在编辑框中
- 求助啊!关于控制台下
- 如何以操作文件名的方式在内存中存储文件数据?在window2000中、能否用VC++编程建立虚拟磁盘?
- 谁有Cosmoplayer SDK的资料
- 请教:有没有人做过ADO的短线重连
- 怎样实现手机短消息功能?大大送分(100)。
- 快看啦!!!如何在Win98下同时实现两个高度实时的线程?
- 请问在win2000下可以对端口进行读写吗?
- 让我发愁的CFile和CString? 大家帮看看
看看我的代码,是截获1、2、3健的
CHookApp theApp;
BOOL installhook()
{
hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc,theApp.m_hInstance,0);
return TRUE;
}
LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
if(((DWORD)lParam&0x40000000) && (HC_ACTION==nCode))
{
switch(wParam) //键盘按键标识
{
case '1':sndPlaySound("D:\\WINDOWS\\Application Data\\Microsoft\\WELCOME\\WELCOM98.WAV",SND_ASYNC);break; //当数字键1被按下
case '2':AfxMessageBox("2.wav");break;
case '3':AfxMessageBox("3.wav");break;
}
}
LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam );
return RetVal;
}
#define _WIN32_WINNT 0x0500
楼上的zhuwenzheng gg的方法,我用了,还是原来一样的错误。
出现了连接错误:
rror LNK2001: unresolved external symbol "long __stdcall LauncherHook(int,unsigned int,long)" (?LauncherHook@@YGJHIJ@Z)
Debug/LaunchDLL.dll : fatal error LNK1120: 1 unresolved externals
加在dll的头文件的第一行,则出现与原来一样的问题。sign~~`
好磨人啊!
还是原来的错误
# define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#endif WIN32_LEAN_AND_MEAN