我测试发现,CFileDialog要在安装VC的环境上能弹出来,需要调用AfxOleInit();
而我的这个程序是DCOM的客户端,为了保证与服务端交互数据,又需要调用如下代码:HRESULT hr; hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
_ASSERTE(SUCCEEDED(hr));但是,如果AfxOleInit();放前面调用,就会影响DCOM的使用,如果AfxOleInit();不使用或放在CoInitializeEx后面,就会影响CFileDialog的使用,两者之间有冲突,请问哪位高手有办法解决?感觉DCOM一定得用CoInitializeEx(NULL, COINIT_MULTITHREADED),那么是否CFileDialog不使用AfxOleInit()用其他方式可以?
而我的这个程序是DCOM的客户端,为了保证与服务端交互数据,又需要调用如下代码:HRESULT hr; hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
_ASSERTE(SUCCEEDED(hr));但是,如果AfxOleInit();放前面调用,就会影响DCOM的使用,如果AfxOleInit();不使用或放在CoInitializeEx后面,就会影响CFileDialog的使用,两者之间有冲突,请问哪位高手有办法解决?感觉DCOM一定得用CoInitializeEx(NULL, COINIT_MULTITHREADED),那么是否CFileDialog不使用AfxOleInit()用其他方式可以?
如果只使用CoInitializeEx(NULL, COINIT_MULTITHREADED)就会出现CFileDialog弹不出对话框,两个同时使用,谁在前,谁有效,所以不知道有什么方法解决?
CoInitializeEx(NULL, COINIT_MULTITHREADED)
// OLE initialization & terminationBOOL AFXAPI AfxOleInit()
{
_AFX_THREAD_STATE* pState = AfxGetThreadState();
ASSERT(!pState->m_bNeedTerm); // calling it twice? // Special case DLL context to assume that the calling app initializes OLE.
// For DLLs where this is not the case, those DLLs will need to initialize
// OLE for themselves via OleInitialize. This is done since MFC cannot provide
// automatic uninitialize for DLLs because it is not valid to shutdown OLE
// during a DLL_PROCESS_DETACH.
if (afxContextIsDLL)
{
pState->m_bNeedTerm = -1; // -1 is a special flag
return TRUE;
} // first, initialize OLE
SCODE sc = ::OleInitialize(NULL);
if (FAILED(sc))
{
// warn about non-NULL success codes
#ifdef _DEBUG
TRACE(traceOle, 0, _T("Warning: OleInitialize returned scode = %s.\n"),
AfxGetFullScodeString(sc));
#endif
goto InitFailed;
}
// termination required when OleInitialize does not fail
pState->m_bNeedTerm = TRUE; // hook idle time and exit time for required OLE cleanup
CWinThread* pThread; pThread = AfxGetThread();
ASSERT(pThread);
pThread->m_lpfnOleTermOrFreeLib = AfxOleTermOrFreeLib; // allocate and initialize default message filter
if (pThread->m_pMessageFilter == NULL)
{
pThread->m_pMessageFilter = new COleMessageFilter;
ASSERT(AfxOleGetMessageFilter() != NULL);
AfxOleGetMessageFilter()->Register();
}
return TRUE;InitFailed:
AfxOleTerm();
return FALSE;
}Applications that do not require the additional functionality enabled by OleInitialize should call CoInitializeEx instead of OleInitialize.
pThread->m_pMessageFilter = new COleMessageFilter;
ASSERT(AfxOleGetMessageFilter() != NULL);
AfxOleGetMessageFilter()->Register();但是,也有一个问题,OleInitialize(NULL)与CoInitializeEx()有什么区别?对于CFileDialog的处理有什么不同?