title: COM, VARIANT containing BSTR. Who allocates?
body: <p>OK, so I couldn't really think of an apropos title that summarizes this.</p>
  
  <p>The IPrintPipelinePropertyBag interface has the method AddProperty which aptly enough "adds a property to a property bag."</p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/aa506384.aspx" rel="noreferrer" title="IPrintPipelinePropertyBag::AddProperty">http://msdn.microsoft.com/en-us/library/aa506384.aspx</a></p>
  
  <blockquote>
    <p>AddProperty(   [in, string] const
    wchar_t  *pszName,   [in] const
    VARIANT  *pVar   );</p>
  </blockquote>
  
  <p>We use the following code to add a string to the property bag.</p>
  
  <pre><code>CComVariant varProperty = CComBSTR(someString);
  pPrintPropertyBag-&gt;AddProperty(L"SOME_PROPERTY", &amp;varFilename);
  </code></pre>
  
  <p>It's pretty obvious, though, that the CComBSTR and CComVariant that is created goes out of scope after a while.  I'm not sure if the PropertyBag handles the string and makes its own copy. Since we can store all kinds of stuff inside a VARIANT, this shouldn't be the case.</p>
  
  <p>Assuming the string isn't handled, my question is, what is the pattern for doing this in COM? How should I  pass a VARIANT that contains an allocated string, make that string available for other threads even if the thread that called AddProperty died first, and de-allocate the string properly?</p>