Two Methods for resource switching in DLL, dll resource switching method
Method 1:
AFX_MANAGE_STATE (AfxGetAppModuleState (); // MFC extension dll
Or
AFX_MANAGE_STATE (AfxGetStaticModuleState (); // Regular dll
Method 2:
HMODULE hDLL = GetModuleHandle ("SourceChange. dll "); HINSTANCE hEXE = AfxGetResourceHandle (); AfxSetResourceHandle (HINSTANCE) hDLL); // you can specify the resource module handle as the DLL module .... // Resource loading AfxSetResourceHandle (hEXE); // switch to the EXE Resource
[NOTE 1 ];
Some resource loading functions need to specify the resource handle. Pay attention to the use of AfxGetInstanceHandle () and AfxGetResourceHandle ().
For example:
LoadCursor (), LoadImage (), and so on.
[NOTE 2 ];
Difference between GetModuleHandle (), AfxGetInstanceHandle (), and 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 ). if the parameter is null, the obtained is the exe handle that calls the DLL, that is, the application handle, rather than the DLL handle. If you want to obtain the current DLL handle, enter the DLL name. 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. the returned result is an application handle. However, if this function is called from within an mfc usrdll version DLL, the returned result is the DLL handle 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. Because it is returned from AfxGetInstanceHandle (), it returns the same value as AfxGetInstanceHandle.