0

我现在正在将一个大型软件从 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它每次都可以正常工作,除非最后一次失败并出现此异常

4

1 回答 1

0

据我在调用堆栈中看到的,当你的 DLL 被卸载或加载时要执行的代码接缝。

当这是“加载代码”时,问题出现了:为什么要再次加载 LDL。

但是在 DllMain 中使用 COM 一点都不好。请参阅此处 COM 不应该在 DllMain 代码中使用。

我想你的 DLL 在 MFC 已经调用 CoUninitialize 之后被卸载。或者您的 DLL 被某些代码重新加载,这些代码不应在您的应用程序关闭时执行。

于 2013-11-11T08:29:10.707 回答