问题描述
我本来用VC6.0写的DLL。当exe退出的时候``宿主程序还是正常的运行.转到vs2003后`当exe退出时`宿主就出现内存出错`查百度`说是托管和非托管的问题`我看配置都是属于非托管的;-------------------------------------------DLL代码--------------------------------------------------------CMain.cpp就一个dialog资源`#include"stdafx.h"#include"ApiHook.h"#include"CMain.h"#ifdef_DEBUG#definenewDEBUG_NEW#endifBEGIN_MESSAGE_MAP(CApiHookApp,CWinApp)END_MESSAGE_MAP()CApiHookApp::CApiHookApp(){}//唯一的一个CApiHookApp对象CApiHookApptheApp;//CApiHookApp初始化BOOLCApiHookApp::InitInstance(){CWinApp::InitInstance();returnTRUE;}extern"C"__declspec(dllexport)boolSetHookGame(DWORDTreadID,DWORDSHUAA,DWORDiDate);//安装HOOKextern"C"__declspec(dllexport)boolUnstallHook();//卸载DLLstaticHHOOKhHook=NULL;//钩子句柄staticHINSTANCEhInst;//当前DLL句柄staticHWNDhwnd;LRESULTCALLBACKMyProc(intnCode,WPARAMwParam,LPARAMlParam);//安装钩子函数bool__declspec(dllexport)SetHookGame(DWORDTreadID,DWORDSHUAA,DWORDiDate){if(TreadID!=0&&SHUAA==0x90)//0x5566{//安装指定线程的钩子hHook=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)MyProc,theApp.m_hInstance,TreadID);if(hHook!=NULL){returntrue;}else{UnhookWindowsHookEx(hHook);returnfalse;}}else{UnhookWindowsHookEx(hHook);returnfalse;}}//---------------------------------------------------------------------------//钩子函数LRESULTCALLBACKMyProc(intnCode,WPARAMwParam,LPARAMlParam){if(nCode<0)return(CallNextHookEx(hHook,nCode,wParam,lParam));if(((DWORD)lParam&0x40000000)&&(HC_ACTION==nCode))//有键按下{if(wParam==VK_F12){if(!DLLMain){AFX_MANAGE_STATE(AfxGetStaticModuleState());DLLMain=newCCMain();CWnd*pCWnd=CWnd::GetForegroundWindow();DLLMain->Create(IDD_DLG,pCWnd);DLLMain->ShowWindow(SW_SHOW);}else{DLLMain->ShowWindow(DLLMain->IsWindowVisible()?SW_HIDE:SW_SHOW);}}}return(CallNextHookEx(hHook,nCode,wParam,lParam));}//---------------------------------------------------------------------------bool__declspec(dllexport)UnstallHook()//卸载DLL{return::UnhookWindowsHookEx(hHook);}//---------------------------------------------------------------------------
解决方案
解决方案二:
学习
解决方案三:
UP
解决方案四:
有可能是编译器问题,在05里遇到过,郁闷了很长时间,可程序拿到其他人机器上,同样的工程、代码就Pass!!很无奈啊@@
解决方案五:
半个月了,解决了吗?
解决方案六:
自己解决了..
解决方案七:
不知,帮顶