VC6.0 m_pConnection.CreateInstance 问题

liaogang01 2011-02-24 02:40:06
m_pConnection.CreateInstance时报 Access Violation,应该是内存泄漏,但后面Open Connectstr没问题程序能正常运行。这是怎么回事?


::CoInitialize(NULL);
HRESULT hr;
_ConnectionPtr m_pConnection;

hr=m_pConnection.CreateInstance(__uuidof(Connection));


if (SUCCEEDED(hr))
{
AfxMessageBox("You are now Connected!",NULL,MB_OK); //Not Executed

}
else if(FAILED(hr))
AfxMessageBox("Not able to connect to DB!",NULL,MB_OK); //Executed


---------
output 中显示如下
First-chance exception in testADOConn.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
...全文
180 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
liaogang01 2011-02-24
  • 打赏
  • 举报
回复
try{
m_pConnection.CreateInstance(__uuidof(Connection));
}
catch(_com_error e){
CString str;
str.Format(L"%s",(LPCTSTR)e.Description());
AfxMessageBox(str);
}


捕获不到错误,可以继续执行
liaogang01 2011-02-24
  • 打赏
  • 举报
回复
m_pConnection=NULL; 加了也没用
liaogang01 2011-02-24
  • 打赏
  • 举报
回复
output 中显示如下
First-chance exception in testADOConn.exe (KERNEL32.DLL): 0xC0000005: Access Violation.
猞猁狲 2011-02-24
  • 打赏
  • 举报
回复

try{
m_pConnection.CreateInstance(__uuidof(Connection));
}
catch(_com_error e){
CString str;
str.Format(L"%s",(LPCTSTR)e.Description());
AfxMessageBox(str);
}


看看打出什么错误信息
ouyh12345 2011-02-24
  • 打赏
  • 举报
回复
不是内存泄漏

_ConnectionPtr m_pConnection = NULL;

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧