Two Methods for resource switching in DLL, dll resource switching method

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.