首页 新闻 赞助 找找看

exe调用dll,当exe关闭后 宿主出错退出了。怎么回事?VC很正常

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