Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
if I create a BSTR in C++, do I need to release it ?
If I create a BSTR in my C++ code calling Excel, do I need to explicitly
release the VARIANT holding the BSTR after I call Excel ? VARIANT range; VariantInit ( & range); range.vt = VT_BSTR; _bstr_t address = _bstr_t (cellAddress.c_str ()); range.bstrVal = address; OLEMethod (DISPATCH_PROPERTYGET, & result1, pExcelSheet, L"Range", 1, range); Thanks, Lynn |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
if I create a BSTR in C++, do I need to release it ?
Yes, you have to.
For example , Microsoft's sample code is doing a same thing. In http://support.microsoft.com/kb/238393/en-us Thanks. I was really hoping that the _bstr_t function would automatically release the BSTR when it's destructor got called at the end of the block. Lynn |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
if I create a BSTR in C++, do I need to release it ?
Sorry , I have not noticed that you are using _bstr_t until now.
What you have said is right. The _bstr_t class automatically doesSysFreeString for you in its destructer. You don't have to do SysFreeString in this case. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
if I create a BSTR in C++, do I need to release it ?
Sorry , I have not noticed that you are using _bstr_t until now.
What you have said is right. The _bstr_t class automatically doesSysFreeString for you in its destructer. You don't have to do SysFreeString in this case. Thanks for confirming that ! Lynn |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
BSTR to char* Help! | Excel Programming | |||
Is this release buggy? | Excel Discussion (Misc queries) | |||
Release Memory | Excel Discussion (Misc queries) | |||
Suggestions for the Next Release | Excel Discussion (Misc queries) | |||
Cannot release cell | Excel Discussion (Misc queries) |