[已关闭问题]
关闭于 2008-01-29 17:11
我本来用VC6.0写的DLL。当exe退出的时候``宿主程序还是正常的运行. <BR>转到vs2003后`当exe退出时`宿主就出现内存出错`查百度`说是托管和非托管的问题`我看配置都是属于非托管的; <BR><BR><BR>-------------------------------------------DLL代码-------------------------------------------------------- <BR>CMain.cpp就一个dialog资源` <BR><BR><BR>#include "stdafx.h" <BR>#include "ApiHook.h" <BR>#include "CMain.h" <BR>#ifdef _DEBUG <BR>#define new DEBUG_NEW <BR>#endif <BR><BR>BEGIN_MESSAGE_MAP(CApiHookApp, CWinApp) <BR>END_MESSAGE_MAP() <BR><BR><BR>CApiHookApp::CApiHookApp() <BR>{ <BR><BR>} <BR><BR><BR>// 唯一的一个 CApiHookApp 对象 <BR><BR>CApiHookApp theApp; <BR><BR><BR>// CApiHookApp 初始化 <BR><BR>BOOL CApiHookApp::InitInstance() <BR>{ <BR>CWinApp::InitInstance(); <BR><BR>return TRUE; <BR>} <BR><BR>extern "C" __declspec(dllexport) bool SetHookGame(DWORD TreadID,DWORD SHUAA,DWORD iDate); //安装HOOK <BR>extern "C" __declspec(dllexport) bool UnstallHook(); //卸载DLL <BR><BR>static HHOOK hHook = NULL; // 钩子句柄 <BR>static HINSTANCE hInst; // 当前DLL句柄 <BR>static HWND hwnd; <BR>LRESULT CALLBACK MyProc(int nCode, WPARAM wParam, LPARAM lParam); <BR><BR><BR>// 安装钩子函数 <BR>bool __declspec(dllexport) SetHookGame(DWORD TreadID,DWORD SHUAA,DWORD iDate) <BR>{ <BR> if(TreadID!=0 && SHUAA == 0x90) //0x5566 <BR> { <BR> // 安装指定线程的钩子 <BR> hHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)MyProc,theApp.m_hInstance,TreadID); <BR> if (hHook != NULL) <BR> { <BR> return true; <BR> } <BR> else <BR> { <BR> UnhookWindowsHookEx(hHook); <BR> return false; <BR> } <BR> } <BR> else <BR> { <BR> <BR>&am