VC扩展DLL资源切换

来源:互联网 发布:泉州广电网络营业厅 编辑:程序博客网 时间:2024/04/27 06:56

在网上找了很久都不能满足自己的要求,最后自己动手写了个

1、在DllMain.cpp中加入

 

AFX_EXTENSION_MODULE GetDllModule(){return AmjeGraphicDLL;//对应改变成自己的Dll}


2、主要切换类

extern AFX_EXTENSION_MODULE GetDllModule();class CChangeModuleStates{public:CChangeModuleStates(){m_pModuleState = AfxGetModuleState();m_hInstanceOld = m_pModuleState->m_hCurrentInstanceHandle;m_hResourceOld = m_pModuleState->m_hCurrentResourceHandle;m_pModuleState->m_hCurrentInstanceHandle = GetDllModule().hModule;m_pModuleState->m_hCurrentResourceHandle = GetDllModule().hResource;}~CChangeModuleStates(){m_pModuleState->m_hCurrentInstanceHandle = m_hInstanceOld;m_pModuleState->m_hCurrentResourceHandle = m_hResourceOld;}private:AFX_MODULE_STATE*m_pModuleState;HINSTANCEm_hInstanceOld;HINSTANCEm_hResourceOld;};


3、在需要调用的地方声明一个类实例