在看到VC下用ADO访问数据库的时候遇到的_vatiant_t,后发现他是一个结构体,为什么从数据库里GetCollect出的数据要先存在用_variant_t定义的变量中,然后用(_bstr_t)作强制类型转换才能存入CString,有的时候还要(LPCTSTR)(_bstr_t)
ex: CString csTemp;
csTemp = (LPCTSTR)(_bstr_t)(m_pTRecordset->GetCollect("ID"));
不解,不懂COM,希望能得到指教。还有一个,Recordset的Open方法有5个参数recordset.Open (Source, ActiveConnection, CursorType, LockType, Options)
程序中:
m_pRecordset->Open("SELECT * FROM users",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
第二个参数ActiveConnection的解释实在没看懂,还望高手赐教 谢谢
ex: CString csTemp;
csTemp = (LPCTSTR)(_bstr_t)(m_pTRecordset->GetCollect("ID"));
不解,不懂COM,希望能得到指教。还有一个,Recordset的Open方法有5个参数recordset.Open (Source, ActiveConnection, CursorType, LockType, Options)
程序中:
m_pRecordset->Open("SELECT * FROM users",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
第二个参数ActiveConnection的解释实在没看懂,还望高手赐教 谢谢
使用_variant_t是为了统一接口返回类型。2.MSDN中的解释。
_variant_t( IDispatch* pDispSrc, bool fAddRef = true )
Constructs a _variant_t object of type VT_DISPATCH from a COM interface pointer. If fAddRef is true, then AddRef is called on the supplied interface pointer to match the call to Release that will occur when the _variant_t object is destroyed. It is up to you to call Release on the supplied interface pointer. If fAddRef is false, this constructor takes ownership of the supplied interface pointer; do not call Release on the supplied interface pointer.
这段英文解释我没看懂-_-!,是说从一个COM接口指针构造的一个VT_DISPATCH类型的_variant_t对象(什么意思。。) call release on the supplied interface pointer 调用释放提供的接口指针 怎么理解