码迷,mamicode.com
首页 > 其他好文 > 详细

在DLL中资源切换的两中方法

时间:2015-03-19 11:38:29      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:dll   资源切换   getmodulehandle   afxgetinstancehandle   afxsetresourcehandle   

方法一:

AFX_MANAGE_STATE(AfxGetAppModuleState());// MFC扩展dll
AFX_MANAGE_STATE( AfxGetStaticModuleState());//常规Regular dll
方法二:
HMODULE hDLL=GetModuleHandle("SourceChange.dll");  
 HINSTANCE hEXE=AfxGetResourceHandle();  
 AfxSetResourceHandle((HINSTANCE)hDLL); //设定资源模块句柄,指定为DLL模块。
...// 资源的加载
 AfxSetResourceHandle(hEXE); // 切换到EXE资源

【注意1】;
有些资源加载函数需要指定资源句柄,请注意使用AfxGetInstanceHandle()、AfxGetResourceHandle()的使用
如:
LoadCursor()、LoadImage()等等。
【注意2】;
GetModuleHandle()、AfxGetInstanceHandle()和CWinApp->m_hInstance的区别:
1.GetModuleHandle(LPCTSTR lpModuleName)   If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process (.exe file).   如果参数为空,那么获取的就是调用这个DLL 的exe的 句柄,也即application句柄,而不是DLL的句柄
  如果要获得当前DLL的句柄,要传入DLL的名称即可。
2.AfxGetInstanceHandle()    An HINSTANCE to the current instance of the application. If called from within a DLL linked with the USRDLL version of MFC, an HINSTANCE to the DLL is returned.    返回的是一个application的句柄,但是如果这个函数是从一个MFC的USRDLL版本DLL的内部被调用,那么返回的就是这个DLL的句柄
3.CWinApp->m_hInstance   The m_hInstance data member is a handle to the current instance of the application running under Windows. This is returned by the global function AfxGetInstanceHandle. m_hInstance is a public variable of type HINSTANCE.   因为它是从 AfxGetInstanceHandle()返回来获得的,所以跟AfxGetInstanceHandle()的返回值一样。

在DLL中资源切换的两中方法

标签:dll   资源切换   getmodulehandle   afxgetinstancehandle   afxsetresourcehandle   

原文地址:http://blog.csdn.net/cbnotes/article/details/44452661

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!