在COM组件中获取资源

先定义两个全局函数:

static AFX_EXTENSION_MODULE extensionDLL;<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

int resource_counter = 0;

HINSTANCE save_hInstance = NULL;

void get_DLL_resource(void)

{

/* this function changes the resource handle to that of the DLL */

//这个函数改变资源句柄使其指向DLL

if (resource_counter == 0)

{

save_hInstance = AfxGetResourceHandle();

AfxSetResourceHandle(extensionDLL.hModule);

}

resource_counter++;

}

//接着你需要其它函数来恢复资源句柄

void reset_DLL_resource(void)

{

/* this function restores the resource handle set by

'get_DLL_resource()' */

if (resource_counter > 0)

resource_counter--;

if (resource_counter == 0)

AfxSetResourceHandle(save_hInstance);

}

 

在获取资源前调用get_DLL_resource(),在获取资源后调用reset_DLL_resource()

如下:

                  get_DLL_resource();

                  

                  CDlgAdd dlg;

                  dlg.pTree = &m_treeAddr;

                  dlg.m_strName = strUser;

                   iRet= dlg.DoModal();

                  

                  reset_DLL_resource();

 

阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭