【问题标题】:access violation (c system exception code : c0000005 ) while accessing ccomptr pointer and application got crash访问 ccomptr 指针和应用程序崩溃时访问冲突(c 系统异常代码:c0000005)
【发布时间】:2011-09-20 12:29:32
【问题描述】:

访问计算机时出现访问冲突错误。 该错误不一致,只能在尝试访问大量数据时重现。 我有 2900 个组件,每个组件我都调用一个函数。在这个函数中,我正在访问一个计算机,而这个应用程序在随机位置崩溃,如 200、210、2500 等。崩溃时的位置不固定。

此问题特定于具有以下配置的系统: 窗口服务器 2003 R2 至强 CPU , 2.66 GHz 2 GB 内存

这是我的代码

XGGraphicAttribute* pAttr = pExtraGraphicInfo->GetAttribute();
if(pAttr)
{
    DBAttributes* db_attributes = NULL;

    db_attributes = static_cast<DBAttributes*> (pAttr->GetDBAttributes());

    CComPtr<IEPGraphicData> pIEPGraphicData;

    if(db_attributes)
    {
        pIEPGraphicData = db_attributes->GetGraphicData(); // here my app got crashed 
    }

}


IEPGraphicData* DBAttributes::GetGraphicData () const
{
    return m_pIEPGraphicData;
}

【问题讨论】:

  • db_attributes 的值是多少?
  • 调用是否从一个 DLLL 转到另一个?
  • 1. m_pIEPGraphicData 是一个 CComPtr,它分配给 pIEPGraphicData,它也是 CComPtr 的一种类型。 2. db_attributes 是一个 DBAttributes 类指针。 3.调用不去其他dll调用。
  • 这里为什么需要 static_cast - pAttr->GetDBAttributes() 实际返回什么类型?

标签: c++ visual-c++ com mfc


【解决方案1】:

可能性:

  1. GetGraphicData() 返回的对象可能不支持 IEPGraphicData 接口。我希望智能指针分配会导致空指针,而不是访问冲突。

  2. 已从您的脚下删除了 db_attributes 对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 2020-05-24
    • 1970-01-01
    • 1970-01-01
    • 2010-11-27
    相关资源
    最近更新 更多