怎么调用资源dll文件

xulingjia3 xulingjia3 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我建了一个纯资源dll文件"OneTest.dll" (MFC appWizard[DLL])
里面有bmp文件和string


然后在MFC应用程序中调用,代码如下:

BOOL COneTestEXEApp::InitInstance()
{

m_hInstance = AfxGetResourceHandle();
m_hResourseHandle = LoadLibrary("OneTest.dll");

if (m_hResourseHandle)
{
AfxSetResourceHandle(m_hResourseHandle);
}
else
{
AfxMessageBox("Load library error!");
PostQuitMessage(1);
return TRUE;
}

AfxEnableControlContainer();

COneTestEXEDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{

}
else if (nResponse == IDCANCEL)
{
}


但是执行int nResponse = dlg.DoModal();时对话框出不来
调试进入CDialog::DoModal方法发现

int CDialog::DoModal()
{
// can be constructed with a resource template or InitModalIndirect
ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
m_lpDialogTemplate != NULL);

// load resource as necessary
LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
HGLOBAL hDialogTemplate = m_hDialogTemplate;
HINSTANCE hInst = AfxGetResourceHandle();
if (m_lpszTemplateName != NULL)
{
hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
hDialogTemplate = LoadResource(hInst, hResource);
}
if (hDialogTemplate != NULL)
lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate);

// return -1 in case of failure to load the dialog template resource
if (lpDialogTemplate == NULL)
return -1;





HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
返回值为空导致程序退出,请教各位这是怎么回事啊.
是我dll文件有问题吗?应该怎样解决.
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
xulingjia3
进程/线程/DLL 15,466 成员 49,169 内容