SetWindowsHookEx不调用HOOKPROC [英] SetWindowsHookEx Not Calling HOOKPROC

查看:120
本文介绍了SetWindowsHookEx不调用HOOKPROC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个DLL,用于将系统挂钩插入所有进程.经过大量的工作,我终于使它得以编译并运行而没有错误.但是当按下一个键时,它似乎没有在DLL中调用该函数.我的DLL脚本如下:

 #include   "  stdafx.h"
 #include   " 
 #include   <   windows.h  > 
 #include   <   iostream  > 
 #include   <   stdio.h  > 

#ifdef _DEBUG
 #define新的DEBUG_NEW
 #endif

提示提示
HHOOK hhk;


LRESULT CALLBACK wireKeyboardProc( int 代码,WPARAM wParam,LPARAM lParam){
printf(" );
CallNextHookEx(hhk,code,wParam,lParam);
返回  0 ;
}

外部 "   __ declspec ( dllexport ) void  install(){
hhk = SetWindowsHookEx(WH_KEYBOARD_LL,wireKeyboardProc,hinst, 0 );
printf(" );
}
外部 "   __ declspec ( dllexport ) void  uninstall(){
UnhookWindowsHookEx(hhk);
}

/*   BOOL WINAPI DllMain(__在HINSTANCE hinstDLL中,
  在DWORD fdwReason中,
  __in LPVOID lpv保留
  ){

 hinst = hinstDLL;
 返回TRUE;
}; */

BEGIN_MESSAGE_MAP(CHookDLLApp,CWinApp)
END_MESSAGE_MAP()

CHookDLLApp :: CHookDLLApp()
{

}

CHookDLLApp theApp;

布尔CHookDLLApp :: InitInstance()
{
CWinApp :: InitInstance();

返回 TRUE;
} 


DllMain已被注释掉,因为它生成一个错误消息,指出它是重复项.
主文件的cpp文件的内容:

 #include   ><   windows.h  > 
 #include   <   stdio.h  > 
 #include   <   cstdlib  > 
 #include   <  字符串 > 
  int  main( int  argv [])
{
    HINSTANCE hinst = LoadLibrary(" );
    如果(后面== NULL)
    {
        printf(" );
    }
     typedef   void (* Install)();
     typedef   void (*卸载)();
    安装install =(Install)GetProcAddress(hinst," );
    卸载卸载=(卸载)GetProcAddress(hinst," );
    字符 ch;
    安装();
    scanf(& ch);
    卸载();
    返回  0 ;
} 


我在HOOKPROC中放置了一个断点,调试器将不会在那里停下来.任何想法或建议都很好.

解决方案

也许这会有所帮助:
http://www.codeproject.com/KB/DLL/hooks.aspx [ ^ ]



I have created a DLL to inject a system hook into all processes. After a great deal of work I finally got it to compile and run without error. But when a key is pressed it doesn''t seem to call the function in the DLL. My script for the DLL is as follows:

#include "stdafx.h"
#include "HookDLL.h"
#include <windows.h>
#include <iostream>
#include <stdio.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

HINSTANCE hinst;
HHOOK hhk;


LRESULT CALLBACK wireKeyboardProc(int code,WPARAM wParam,LPARAM lParam) {
	printf("2");
	CallNextHookEx(hhk,code,wParam,lParam);
	return 0;
}

extern "C" __declspec(dllexport) void install() { 
	hhk = SetWindowsHookEx(WH_KEYBOARD_LL, wireKeyboardProc, hinst, 0);
	printf("3");
}
extern "C" __declspec(dllexport) void uninstall() {
	UnhookWindowsHookEx(hhk); 
}

/*BOOL WINAPI DllMain(  __in  HINSTANCE hinstDLL,
  __in  DWORD fdwReason,
  __in  LPVOID lpvReserved
  ) {

 hinst = hinstDLL;
 return TRUE;
};*/

BEGIN_MESSAGE_MAP(CHookDLLApp, CWinApp)
END_MESSAGE_MAP()

CHookDLLApp::CHookDLLApp()
{

}

CHookDLLApp theApp;

BOOL CHookDLLApp::InitInstance()
{
	CWinApp::InitInstance();

	return TRUE;
}


The DllMain was commented out because it generated an error saying it was a duplicate.
The contents of the cpp file for the main file:

#include <windows.h>
#include <stdio.h>
#include <cstdlib>
#include <string>
int main(int argv[])
{
    HINSTANCE hinst = LoadLibrary("HookDLL.dll");
    if (hinst == NULL)
    {
        printf("null hinst");
    }
    typedef void (*Install)();
    typedef void (*Uninstall)();
    Install install = (Install) GetProcAddress(hinst, "install");
    Uninstall uninstall = (Uninstall) GetProcAddress(hinst, "uninstall");
    char ch;
    install();
    scanf(&ch);
    uninstall();
    return 0;
}


I placed a break point in the HOOKPROC and the debugger will not stop there. Any ideas or suggestions would be great.

解决方案

Perhaps this will help:
http://www.codeproject.com/KB/DLL/hooks.aspx[^]


<code>
HINSTANCE hinst;//

hhk = SetWindowsHookEx(WH_KEYBOARD_LL, wireKeyboardProc, hinst, 0);



//Todo::you can''t Distribution of instances!!! Plase  Distribution of instances

</code>


这篇关于SetWindowsHookEx不调用HOOKPROC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆