我现在正在将一个大型软件从 OWL 移动到 MFC,大部分任务已经完成,但是当应用程序关闭时我遇到了很多类似这样 的 问题调用堆栈
msdart.dll!_UMSEnterCSWraper() Unknown
msado15.dll!ATL::AtlModuleGetClassObject(struct ATL::_ATL_MODULE *,struct _GUID const &,struct _GUID const &,void * *) Unknown
msado15.dll!ATL::CComModule::GetClassObject(struct _GUID const &,struct _GUID const &,void * *) Unknown
msado15.dll!_DllGetClassObject@12() Unknown
ole32.dll!CClassCache::CDllPathEntry::DllGetClassObject(const _GUID & rclsid, const _GUID & riid, IUnknown * * ppUnk, int fMakeValid) Line 3317 C++
ole32.dll!CClassCache::CDllFnPtrMoniker::BindToObject(const _GUID & riid, void * * ppvResult) C++
ole32.dll!CClassCache::SearchForLoadedClass(const ACTIVATION_PROPERTIES & ap, CClassCache::CDllClassEntry * * ppDCE) C++
ole32.dll!ICoCreateInstanceEx(const _GUID & Clsid, IUnknown * punkOuter, unsigned long dwClsCtx, _COSERVERINFO * pServerInfo, unsigned long dwCount, unsigned long dwActvFlags, tagMULTI_QI * pResults, ActivationPropertiesIn * pActIn) Line 1163 C++
ole32.dll!CComActivator::DoCreateInstance(const _GUID & Clsid, IUnknown * punkOuter, unsigned long dwClsCtx, _COSERVERINFO * pServerInfo, unsigned long dwCount, tagMULTI_QI * pResults, ActivationPropertiesIn * pActIn) Line 332 C++
ole32.dll!CoCreateInstanceEx(const _GUID & Clsid, IUnknown * punkOuter, unsigned long dwClsCtx, _COSERVERINFO * pServerInfo, unsigned long dwCount, tagMULTI_QI * pResults) Line 157 C++
ole32.dll!CoCreateInstance(const _GUID & rclsid, IUnknown * pUnkOuter, unsigned long dwContext, const _GUID & riid, void * * ppv) Line 110 C++
> DBCore.dll!_com_ptr_t<_com_IIID<ADODB::_Command,&_GUID_b08400bd_f9d1_4d02_b856_71d5dba123e9> >::CreateInstance(const _GUID & rclsid, IUnknown * pOuter, unsigned long dwClsContext) Line 586 C++
DBCore.dll!TADOCommand::Init(TADOConnection * connection) Line 32 C++
DBCore.dll!TADOCommand::TADOCommand(TADOConnection * connection) Line 8 C++
AmnDbase.dll!TQuery::Init() Line 335 C++
AmnDbase.dll!TQuery::TQuery(const TDatabase * db, TTable * Tbl) Line 304 C++
AmnDbase.dll!TDirectQuery::TDirectQuery(const TDatabase * db) Line 932 C++
AmnDbase.dll!CommitUnsavedTransactions(TDatabase * db) Line 674 C++
AmnDbase.dll!TDatabase::Disconnect() Line 427 C++
AmnDbase.dll!TDatabase::CloseDb() Line 455 C++
AmnDbase.dll!TDatabase::Close() Line 417 C++
AmnLib2.dll!TStoreFile::Close() Line 3275 C++
AmnLib2.dll!TStoreFile::~TStoreFile() Line 1040 C++
AmnLib2.dll!`GetStoreFile'::`2'::`dynamic atexit destructor for 'StoreFile''() C++
AmnLib2.dll!_CRT_INIT(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 415 C
AmnLib2.dll!__DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 526 C
AmnLib2.dll!_DllMainCRTStartup(void * hDllHandle, unsigned long dwReason, void * lpreserved) Line 476 C
这是调用 CreateInstance 的代码
/// Init the command instance.
void TADOCommand::Init( TADOConnection* connection)
{
m_CmdText = "";
m_nRecordsAffected = 0;
m_Command = NULL;
m_ResultSet = NULL;
m_CmdConnection = NULL;
m_CmdRecordset = NULL;
if( connection->IsNull())
return;
m_Command.CreateInstance( __uuidof( Command));
SetConnection( connection);
SetCommandTimeOut( connection->GetCommandTimeout());
}
我希望代码在不更改任何代码的情况下继续工作,特别是在数据库层中,这是因为从 MFC 调用了 couninitialize 吗?我怎样才能检测到或解决这个问题?
并且 m_Command 被定义为
_CommandPtr m_Command;
它是 com 接口首先它设置为 null 然后调用CreateInstance它每次都可以正常工作,除非最后一次失败并出现此异常