Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
BSTR to char* Help! Ai Excel Programming 5 July 7th 10 02:41 PM
Is this release buggy? Matt Morgan Excel Discussion (Misc queries) 1 December 19th 06 03:44 PM
Release Memory Jeff Excel Discussion (Misc queries) 1 September 25th 06 09:28 PM
Suggestions for the Next Release ExcelPro Excel Discussion (Misc queries) 0 May 24th 06 07:45 AM
Cannot release cell MEvans Excel Discussion (Misc queries) 1 January 29th 05 02:06 PM


All times are GMT +1. The time now is 02:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"