::CoInitialize(NULL);
   HRESULT hr;
   try
   {
     hr=this->m_pConnection.CreateInstance("ADODB.Connection");
     if(SUCCEEDED(hr))
     {
return;
 }
   }
   catch(_com_error e)///捕捉异常
......
以上是初始化的code
然后在程序结束的时候调用
if (this->IsOpen()) 
{
this->m_pConnection->Close();
   this->m_pConnection->Release();  ---〉我释放了的呀!
this->m_pConnection=NULL; 
}
::CoUninitialize();
This代表同一个类。可惜在调试的时候
// Releases only if the interface is not null.
// The interface is not set to NULL.
//
void _Release() throw()
{
if (m_pInterface != NULL) {
m_pInterface->Release();-----〉错误发生时候停在这个地方,说是unhandle .....
}
}
可是我明明释放过了呀!
对于com我十分的不了解!所以还请大家帮忙!
谢谢喽!

解决方案 »

  1.   

    if (this->m_pConnection->IsOpen()) //这里是不是
    {
    this->m_pConnection->Close();
      

  2.   

    析构函数在退出作用域之前最后执行,所以你的程序很可能在CoUninitialize之后执行了析构函数中的Release。
      

  3.   

    this->m_pConnection->Release();  ---〉我释放了的呀!
    m_pConnection是不是一个智能指针?如果是智能指针,不需要调用release()函数。智能指针在析构函数中自动调用,如果你要提前释放智能指针的引用,你这样调用代码看看。
    this->m_pConnection.Release();  ---〉注意这里用.操作符。
      

  4.   

    我使用ADODB的聪明指针时也会经常碰到莫明其妙的问题。
    后来就不用_ConnectionPtr而直接使用_Connectoin*就一切OK了,你也可以试试看。_Connectoin *pConn = NULL; ::CoInitialize(NULL);
    ASSERT(SUCCEEDED(::CoCreateInstance(
    __uuidof(Connection), NULL, CLSCTX_INPROC_SERVER,
    __uuidof(_Connection), (LPVOID*) &pConn)));
      

  5.   

    To Ah(蓝过天) 
    还真的是这个样子呢!很奇怪的说!不知道这个该作何解释呢!?