title: How to best convert CString to BSTR to pass it as an "in" parameter into a COM method?
body: <p>I need to convert a <code>CString</code> instance into a properly allocated <code>BSTR</code> and pass that <code>BSTR</code> into a COM method. To have code that compiles and works indentically for both ANSI and Unicode I use <code>CString::AllocSysString()</code> to convert whatever format <code>CString</code> to a Unicode BSTR.</p>
  
  <p>Since noone owns the returned BSTR I need to take care of it and release it after the call is done in the most exception-safe manner posible and with as little code as possible.</p>
  
  <p>Currently I use <code>ATL::CComBSTR</code> for lifetime management:</p>
  
  <pre><code> ATL::CComBSTR converted;
   converted.Attach( sourceString.AllocSysString() ); //simply attaches to BSTR, doesn't reallocate it
   interface-&gt;CallMethod( converted );
  </code></pre>
  
  <p>what I don't like here is that I need two separate statements to just construct the <code>ATL::CComBSTR</code> bound to the convertion result.</p>
  
  <p>Is there a better way to accomplish the same task?</p>