View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Akihito Yamashiro[_2_] Akihito Yamashiro[_2_] is offline
external usenet poster
 
Posts: 14
Default if I create a BSTR in C++, do I need to release it ?

Hi.

Yes, you have to.
For example , Microsoft's sample code is doing a same thing.
In http://support.microsoft.com/kb/238393/en-us
-----------------------
// Call Documents.Open() to open C:\Doc1.doc
IDispatch *pDoc;
{
VARIANT result;
VariantInit(&result);
VARIANT x;
x.vt = VT_BSTR;
x.bstrVal = ::SysAllocString(L"C:\\Doc1.doc");

AutoWrap(DISPATCH_METHOD, &result, pDocs, L"Open", 1, x);
pDoc = result.pdispVal;
SysFreeString(x.bstrVal);
}
-----------------------
The variable x.bstrVal is released.