COM interface pointer => _variant_t
Constructs a _variant_t object of type VT_DISPATCH from a COM interface pointer. IffAddRef istrue, thenAddRef is called on the supplied interface pointer to match the call toRelease that will occur when the_variant_t object is destroyed. It is up to you to callRelease on the supplied interface pointer. IffAddRef is false, this constructor takes ownership of the supplied interface pointer; do not callRelease on the supplied interface pointer.
使用一個COM組件的指針構造一個_variant_t類型的對象。
如果fAddRef爲真時,會調用COM組件的AddRef函數爲該組件添加一個引用。AddRef函數和Release函數相對應,當_variant_t銷燬的時候調用會調用Release函數。至於原來的COM組件調用不掉用Release由你自己決定。如果fAddRef爲假時,這個_variant_t對象就取得了這個COM組件的所有權,原來的COM組件就不能再調用Release了。
for example:
_ConnectionPtr m_pConnect;
m_pConnect.CreateInstance("ADODB.Connection");
// 以下幾種情況一樣:
1、_variant_t v1 = (_variant_t)(IDispatch*)m_pConnect;
2、_variant_t v2 = _variant_t((IDispatch*)m_pConnect, true);
3、_variant_t v3 = _variant_t((IDispatch*)m_pConnect, false);
m_pConnect->AddRef();