C程序错误(DebugError)
请教下,我写了个监视记事本的键盘Hook程序。在VC6.0中编译运行后弹出DebugError的错误提示。好像是函数调用约定不对,不知道该怎么解决。另外,程序HOOK功能正常。
我不懂汇编,接触Windows编程也不久。
详细:
The value of ESP was not properly saved across a function call.This is usually a result of
calling a function declared with one calling convention with a function pointer declared
with a different calling convention.
下面附上代码,有两个文件,t.c(exe文件)和fDll.c(Dll文件),分开编译:
//t.c
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR pCmdLine,int iShowcmd)
{
HMODULE hLibrary;
FARPROC fpSethook,fpUnhook;
HWND hParent,hChild;
DWORD dwThread;
hParent=FindWindow(NULL,"jk.txt - 记事本");
hChild=FindWindowEx(hParent,NULL,"Edit",NULL);
dwThread=GetWindowThreadProcessId(hChild,NULL);
hLibrary=LoadLibrary("fDll.dll");
fpSethook=GetProcAddress(hLibrary,"Sethook");
if(dwThread&&hLibrary&&fpSethook)
MessageBox(NULL,"开始安装Hook","",MB_OK);
if(fpSethook(hLibrary,dwThread))
MessageBox(NULL,"函数已返回","",MB_OK);
MessageBox(NULL,"终于成功啦!","",MB_OK);
fpUnhook=GetProcAddress(hLibrary,"Unhook");
if(fpUnhook)MessageBox(NULL,"成功","",MB_OK);
fpUnhook();
FreeLibrary(hLibrary);
MessageBox(NULL,"Start Setup Hook","",MB_OK);
}
//fDll.dll
#include <windows.h>
LRESULT CALLBACK Hookproc(int nCode,WPARAM wParam,LPARAM lParam)
{
MessageBox(NULL,"哈哈","",MB_OK);
return (LRESULT)CallNextHookEx(hHook,nCode,wParam,lParam);
}
__declspec(dllexport) BOOL Sethook(HMODULE hLibrary,DWORD dwThread)
{
hHook=SetWindowsHookEx(WH_KEYBOARD,Hookproc,hLibrary,dwThread);
if(hHook)
return TRUE;
else
return FALSE;
}
__declspec(dllexport) void Unhook()
{
UnhookWindowsHookEx(hHook);
}
有需要可以用QQ讨论:59757359 。也可以留下你的QQ,我加你
[ 本帖最后由 tfitw 于 2009-9-5 12:59 编辑 ]