1、我现在在stdafx.cpp中定义了如下全局变量
CAdoConnection adoConn; // CAdoConnection 是我自己创建的一个对_ConnectionPtr 的封装类;
CAdoRecordset adoRec;  // CAdoRecordset 是我自己创建的一个对_RecordsetPtr 的封装类;2、在stdafx.h中使用了如下引用
extern CAdoConnection adoConn;
extern CAdoRecordset adoRec;3、在程序中没有对这两个全局变量进行引用
   但是在程序退出的时候就会有报错对话框出现(Unhandled exception in test.exe:0xC0000005: Access Violation),我对错误进行了跟踪,错误指向了COMIP.H文件中的“m_pInterface->Release();” void _Release() throw()
{
if (m_pInterface != NULL) {
m_pInterface->Release();
}
}但是,如果我不采用全局变量的时候,程序都能正常执行和退出。请问各位,是不是我的全局变量的定义有问题,还是哪个地方出现了错误?
我的 构造函数 和 构析函数如下:CAdoConnection::CAdoConnection()
{
AfxOleInit();
m_pConnection.CreateInstance("ADODB.Connection");#ifdef _DEBUG
if(m_pConnection==NULL)
{
AfxMessageBox("Connection 对象创建失败! 请确认初始化了COM环境!\r\n");
}
#endif ASSERT (m_pConnection!=NULL);
}CAdoConnection::~CAdoConnection()
{
}CAdoRecordset::CAdoRecordset()
{
m_pConnection = NULL; m_pRecordset.CreateInstance("ADODB.Recordset");
#ifdef _DEBUG
if (m_pRecordset == NULL)
{
AfxMessageBox("RecordSet 对象创建失败! 请确认是否初始化了COM环境.");
}
#endif
ASSERT(m_pRecordset != NULL);
}CAdoRecordset::~CAdoRecordset()
{
}