Exe under Windows uses resources in Dll

Problem: ResourceHandle defaults to InstanceHandle, so using resources in Dll will fail.

Solution: Switch the ResourceHandle to the instance handle of the dynamic library, and switch back to the current instance handle after using the resource.


//Switch from exe to dll, then switch from dll to exe
HINSTANCE hExe = AfxGetResourceHandle();
HINSTANCE hDll = AfxGetInstanceHandle();
hDll = ::GetModuleHandleA("KqGisFrame.dll");
AfxSetResourceHandle(hDll);
CHelloDlg dlg;//The resource of the dialog is located in the dynamic library;
dlg.DoModal();//But the default is to run the instance when loading resources;
AfxSetResourceHandle(hExe);//So switch


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324610974&siteId=291194637