这个DLL为什么有错误?
// Hook1.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "Hook1.h"
//#include "HookApp.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
LRESULT CALLBACK MouseProc(int nCode,WPARAM wParam,LPARAM lParam)
{
LRESULT RetVal= CallNextHookEx(hhk,nCode,wParam,lParam);
return RetVal;
}
// 添加鼠标钩子的安装和卸载函数:
BOOL InstallHook()
{
hhk=::SetWindowsHookEx(WH_MOUSE,MouseProc,hinst,0);
// ….
return true;
}
void UninstallHook()
{
::UnhookWindowsHookEx(hhk);
}
// 再实例化中获得一些参数
BOOL CHookApp::InitInstance() //CHookApp::
{
// 获得dll 实例,进程句柄
hinst=::AfxGetInstanceHandle();
DWORD dwPid=::GetCurrentProcessId();
hProcess=OpenProcess(PROCESS_ALL_ACCESS,0,dwPid);
//调用注射函数
Inject();
return CWinApp::InitInstance();
}
// 好,最重要的注射函数:
void Inject()
{
if (m_bInjected==false)
{ //保证只调用1次
m_bInjected=true;
//获取add.dll中的add()函数
HMODULE hmod=::LoadLibrary("add.dll");
add=(AddProc)::GetProcAddress(hmod,"add");
pfadd=(FARPROC)add;
if (pfadd==NULL)
{
AfxMessageBox("cannot locate add()");
}
// 将add()中的入口代码保存入OldCode[]
_asm
{
lea edi,OldCode
mov esi,pfadd
cld
movsd
movsb
}
NewCode[0]=0xe9;//实际上0xe9就相当于jmp指令
//获取Myadd()的相对地址
_asm
{
lea eax,Myadd
mov ebx,pfadd
sub eax,ebx
sub eax,5
mov dword ptr [NewCode+1],eax
}
//填充完毕,现在NewCode[]里的指令相当于Jmp Myadd
HookOn(); //可以开启钩子了
}
}
// 开启钩子的函数
void HookOn()
{
ASSERT(hProcess!=NULL);
DWORD dwTemp=0;
DWORD dwOldProtect;
//将内存保护模式改为可写,老模式保存入dwOldProtect
VirtualProtectEx(hProcess,pfadd,5,PAGE_READWRITE,&dwOldProtect);
//将所属进程中add()的前5个字节改为Jmp Myadd
WriteProcessMemory(hProcess,pfadd,NewCode,5,0);
//将内存保护模式改回为dwOldProtect
VirtualProtectEx(hProcess,pfadd,5,dwOldProtect,&dwTemp);
bHook=true;
}
// 关闭钩子的函数
void HookOff()//将所属进程中add()的入口代码恢复
{
ASSERT(hProcess!=NULL);
DWORD dwTemp=0;
DWORD dwOldProtect;
VirtualProtectEx(hProcess,pfadd,5,PAGE_READWRITE,&dwOldProtect);
WriteProcessMemory(hProcess,pfadd,OldCode,5,0);
VirtualProtectEx(hProcess,pfadd,5,dwOldProtect,&dwTemp);
bHook=false;
}
// 然后,写我们自己的Myadd()函数
int WINAPI Myadd(int a,int b)
{
//截获了对add()的调用,我们给a,b都加1
a=a+1;
b=b+1;
HookOff();//关掉Myadd()钩子防止死循环
int ret;
ret=add(a,b);
HookOn();//开启Myadd()钩子
return ret;
}
我在网上抄的鼠标钩子DLL,但为什么会有错误。
错误提示
error C2065: 'hhk' : undeclared identifier
error C2065: 'hinst' : undeclared identifier
error C2653: 'CHookApp' : is not a class or namespace name
等等等。。。
我又在Hook1.h文件里面添加了
HHOOK hhk;
HINSTANCE hinst;
但还是有下面一些错误 等等。。。
error C2653: 'CHookApp' : is not a class or namespace name
error C2039: 'AfxGetInstanceHandle' : is not a member of '`global namespace''
error C2065: 'AfxGetInstanceHandle' : undeclared identifier
error C2440: '=' : cannot convert from 'int' to 'struct HINSTANCE__ *'
麻烦哪位先知帮我解决一下啊???