CComBSTR::Attach

附加 BSTRCComBSTR 对象通过设置 m_str 成员对 src

void Attach( 
   BSTR src  
) throw( );

参数

  • src
    [in]附加 BSTR 为对象。

备注

不要将一个普通的宽字符字符串传递给此方法。 编译器无法捕获错误,而运行时将发生错误。

备注

此方法断言 m_str 是否为非NULL

示例

// STDMETHOD(BSTRToUpper)(/*[in, out]*/ BSTR bstrConv);
STDMETHODIMP InplaceBSTRToUpper(BSTR bstrConv)
{
   // Assign bstrConv to m_str member of CComBSTR
   CComBSTR bstrTemp;
   bstrTemp.Attach(bstrConv); 

   // Make sure BSTR is not NULL string 
   if (!bstrTemp)
        return E_POINTER;

   // Make string uppercase 
   HRESULT hr;
   hr = bstrTemp.ToUpper();
   if (hr != S_OK)
       return hr;

   // Set m_str to NULL, so the BSTR is not freed
   bstrTemp.Detach(); 

   return S_OK; 
}

要求

Header: atlbase.h

请参见

参考

CComBSTR 类

CComBSTR::Detach

CComBSTR::operator =