BOOL CTestApp::InitInstance()
{
m_hLangRcDLL=::LoadLibrary("RVMonitorRC.dll");

if (!m_hLangRcDLL)
{
AfxMessageBox("Can't LoadLibrary RVMonitorRC.dll!");
return FALSE;
}

//连接资源 
AfxSetResourceHandle( m_hLangRcDLL );

AfxOleInit();

CoInitialize(NULL);
AfxEnableControlContainer(); // Standard initialization
// If you are not using these features and wish to reduce the size
//  of your final executable, you should remove from the following
//  the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
AFX_MAMAGE_STATE(AfxGetStaticModuleState());
CTestDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
//  application, rather than start the application's message pump.
return FALSE;
}RVMonitorRC.dll是一个封装了资源的DLL,网上查找信息看了看,但是可能有用的这句AFX_MANAGE_STATE(AfxGetStaticModuleState()); AFX_MANAGE_STATE提示无法定义Dll注册的时候显示加载成功,但是注册不了,但是我一个示例程序却可以加载,代码如下:
BOOL CRVMonitorApp::InitInstance()
{
AfxEnableControlContainer(); m_hLangRcDLL=::LoadLibrary("RVMonitorRC.dll"); if (!m_hLangRcDLL)
{
AfxMessageBox("Can't LoadLibrary RVMonitorRC.dll!");
return FALSE;
} //连接资源 
AfxSetResourceHandle( m_hLangRcDLL ); AfxOleInit(); CoInitialize(NULL);#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif CString strClassName, strWindowName;
strWindowName.LoadString(IDS_MAINFRAMETITLE); SetRegistryKey( strWindowName ); int cxFullScreen = GetSystemMetrics(SM_CXSCREEN);
int cyFullScreen = GetSystemMetrics(SM_CYSCREEN); cxFullScreen > 1024 ? cxFullScreen : 1024;
cyFullScreen > 768  ? cyFullScreen : 768; CRect rectDesktop = CRect(0, 0, cxFullScreen, cyFullScreen); CRVMonitorWnd * pFrame = new CRVMonitorWnd;
m_pMainWnd = pFrame;
m_pRVMMainWnd = pFrame; if (pFrame->CreateMainWnd(strWindowName,  WS_POPUP | WS_CLIPCHILDREN, rectDesktop ) == FALSE)
return FALSE; pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow(); return TRUE;
}这个代码加载成功了,我的却失败了不知道什么原因,求高手指点

解决方案 »

  1.   

    只有COM的dll才需要注册,普通dll根本不需要注册
    你第一个代码LoadLibrary到底成功没有?如果成功了,就和加载似乎没有关系。你的第二个实例根本没有载入对话框,不知道和第一个有什么可比性?你第一个代码要成功,CTestDlg对应的资源必须在RVMonitorRC.dll定义才对,你时这样定义的么?
      

  2.   

    没看懂,你要加载dll中的什么资源?
      

  3.   

    第一个代码LoadLibrary成功了,RVMonitorRC.dll定义的资源在后面会调用,目前就是nResponse = -1第二个也没有载入对话框,只是里面有资源,在后面动态创建的时候调用了,我第一个代码也想动态创建的时候调用,但是目前是我主程序都进不去
      

  4.   

    你所有资源都在RVMonitorRC.dll中吗?
      

  5.   

    不是,里面有比如一个工具栏的资源,我就是想把这个工具栏搬到我第一个程序里面,就是这个意思
    比如下面这图,我也不是很需要这个,只是疑惑为什么第一个程序nResponse = -1了
      

  6.   

    如果不是所有资源都在资源dll中,不要SetResourceHandle,在需要的时候再Set.