键盘钩子DLL中函数调用及返回的问题,请高手指点

hyamw 2003-02-14 01:10:41
我写了个键盘钩子函数想实现:
按下热键后给定标志翻转(从而达到关闭功能)
在主调程序中调用dll中的RunOK()函数来返回标志的状态
但是实际运行过程中发现几个问题
热键在别的窗口下无效,只有在调用DLL的程序中按下
热键才有效。但是同样在钩子函数中的显示对话框的函数能正常运行。这是为什么?
附代码如下:
...全文
25 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyamw 2003-02-18
  • 打赏
  • 举报
回复
非常感谢,已经搞定了。
我用另外一种方法也搞定了。
给分....
papaya_stone 2003-02-16
  • 打赏
  • 举报
回复
#pragma data_seg("Shared")
BOOL Run = FALSE;
HHOOK g_hInstance = NULL;
#pragma data_seg()
// Instruct the linker to make the Shared section
// readable, writtable and shared
#pragma comment(linker, "/section:Shared,rws")
papaya_stone 2003-02-16
  • 打赏
  • 举报
回复
//hook.cpp

#pragma data_seg("Shared")
BOOL Run = FALSE;
HHOOK g_hInstance;
#pragma data_seg()
// Instruct the linker to make the Shared section
// readable, writtable and shared
#pragma comment(linker, "/section:Shared,rws")

LRESULT HOOK_API CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)

{
WORD wKey = (WORD)wParam;
if((HIWORD(lParam) & KF_UP) == 0 && HC_ACTION == nCode)
{
if(wKey == VK_ADD)//是热键
{
Run=!Run;
HWND hWnd = ::GetForegroundWindow();

//创建并显示模式对话框
::DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DLGPROC(DialogProc));
}
}
LRESULT RetVal = CallNextHookEx(g_hKeyHook, nCode, wParam, lParam );
return RetVal;
}
BOOL HOOK_API RunOK()
{
return Run;
}


//*********************----hook.H----*********************

HOOK_API BOOL Run;
HOOK_API BOOL RunOK();
hyamw 2003-02-15
  • 打赏
  • 举报
回复
使用WH_JOURNALRECORD如何判断按键?
参数lParam与按键关系是怎样的?(因为我要判断是否是热键)
hyamw 2003-02-15
  • 打赏
  • 举报
回复
哪位帮我看看,上面的代码中RunOK()函数为什么安装完钩子后调用时没有返回值?(只有在安装钩子的时候调用这个函数可以得到正确的返回值)
何哀何欢 2003-02-15
  • 打赏
  • 举报
回复
键盘钩子 用 WH_JOURNALRECORD,很好使,无须DLL
hyamw 2003-02-14
  • 打赏
  • 举报
回复
//hook.cpp
LRESULT HOOK_API CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)

{
WORD wKey = (WORD)wParam;
if((HIWORD(lParam) & KF_UP) == 0 && HC_ACTION == nCode)
{
if(wKey == VK_ADD)//是热键
{
Run=!Run;
HWND hWnd = ::GetForegroundWindow();

//创建并显示模式对话框
::DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hWnd, DLGPROC(DialogProc));
}
}
LRESULT RetVal = CallNextHookEx(g_hKeyHook, nCode, wParam, lParam );
return RetVal;
}
BOOL HOOK_API RunOK()
{
return Run;
}


//*********************----hook.H----*********************

HOOK_API BOOL Run;
HOOK_API BOOL RunOK();

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧