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;
}这个代码加载成功了,我的却失败了不知道什么原因,求高手指点
{
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;
}这个代码加载成功了,我的却失败了不知道什么原因,求高手指点
你第一个代码LoadLibrary到底成功没有?如果成功了,就和加载似乎没有关系。你的第二个实例根本没有载入对话框,不知道和第一个有什么可比性?你第一个代码要成功,CTestDlg对应的资源必须在RVMonitorRC.dll定义才对,你时这样定义的么?
比如下面这图,我也不是很需要这个,只是疑惑为什么第一个程序nResponse = -1了