16,550
社区成员
发帖
与我相关
我的任务
分享
看看 _ConnectionPtr的定义
_COM_SMARTPTR_TYPEDEF(_Connection, __uuidof(_Connection));
#define _COM_SMARTPTR_TYPEDEF(Interface, IID) typedef _COM_SMARTPTR<Interface, &IID> Interface ## Ptr
#define _COM_SMARTPTR _com_ptr_t
综合起来就是
typedef _com_ptr_t< _Connection,__uuidof(_Connection)> _ConnectionPtr;
_ConnectionPtr pConn;是定义了一个模板类的对象。所以调用其成员函数CreateInstance()需要用.;
pConn->Open();
pConn->Close();
pConn.CreateInstance();
pConn.Release();
既然是对象那为什么会用->呢。看看_com_ptr_t的声明里面有这个:
// Allows this class to be used as the interface itself.
// Also provides simple error checking.
//
Interface* operator->() const
{
if (m_pInterface == NULL) {
_com_issue_error(E_POINTER);
}
return m_pInterface;
}
// The Interface.
//
Interface* m_pInterface;
他是重载了->,用pconn->实际上是用了它里面的接口指针。