Get resources in COM components

zhaozj2021-02-16  86

First define two full-bureau functions:

Static AFX_EXTENSION_MODULE EXTENSIONDLL;

Int resource_counter = 0;

Hinstance Save_HINSTANCE = NULL;

Void get_dll_resource (void)

{

/ * this function change the resource handle to what of the dll * /

// This function changes the resource handle to point to the DLL

IF (resource_counter == 0)

{

Save_HINSTANCE = AFXGETRESOURCEHANDLE ();

AFXSetResourceHandle (Extensiondll.hmodule);

}

Resource_counter ;

}

/ / Then you need other functions to restore the resource handle

Void reset_dll_resource (void)

{

/ * this function restore the resource handle set by

'get_dll_resource ()' * /

IF (resource_counter> 0)

Resource_counter--;

IF (resource_counter == 0)

AFXSetResourceHandle (Save_HINSTANCE);

}

Call GET_DLL_RESOURCE () before getting resources, call reset_dll_resource after obtaining resources ()

as follows:

GET_DLL_RESOURCE ();

CDLGADD DLG;

DLG.PTREE = & m_treeaddr;

Dlg.m_strname = struse;

IRET = DLG.DOMODAL ();

RESET_DLL_RESOURCE ();

转载请注明原文地址:https://www.9cbs.com/read-12901.html

New Post(0)