Export (0) Print
Expand All

CComBSTR::Attach

Attaches a BSTR to the CComBSTR object by setting the m_str member to src.

void Attach( 
   BSTR src  
) throw( );

src

[in] The BSTR to attach to the object.

Do not pass an ordinary wide-character string to this method. The compiler cannot catch the error and run time errors will occur.

Note Note

This method will assert if m_str is non-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

Show:
© 2015 Microsoft