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);
}
接下来一点非常重要,只要有可能就必须恢复资源句柄,否则,你将会遇到许多问题.原因是可执行文件必须重画工具条等等,比如说,如果用户移动DLL的对话框,如果资源句柄仍然为DLL的资源,程序就崩溃了,我发现最好恢复句柄的时机在对话框的OnInitDialog()中,这时对话框的模板等已经读出了.