> Lets say I write this line:
> BSTR b = m_pdoc->Getxml ();
[quoted text clipped - 3 lines]
> is written, do I have to take care about deleting "b"? And how do I do it
> ?
Hi,
You can use use SysFreeString for that.
Or you could use _bstr_t instead of BSTR.
It is a wrapper around BSTR, and it will do those things for you

Signature
Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"
Abubakar - 25 Aug 2006 13:48 GMT
wow , cool.
-Ab.
> > Lets say I write this line:
> > BSTR b = m_pdoc->Getxml ();
[quoted text clipped - 15 lines]
> bruno_nos_pam_van_dooren@hotmail.com
> Remove only "_nos_pam"
Hi Abubakar,
> Lets say I write this line:
> BSTR b = m_pdoc->Getxml ();
> where m_pdoc is MSXML2::IXMLDOMDocumentPtr.
> Now "b" contains the xml text. When I exit the function in which this
> line is written, do I have to take care about deleting "b"? And how do
> I do it ?
Actually, I believe your code is incorrect. IXMLDOMDocumentPtr is a compiler-generated
wrapper for the raw COM interface, and does not return a BSTR, but a _bstr_t.
By assigning the return value to a BSTR, you are invoking a conversion operator
on the returned _bstr_t, which is subsequently destroyed. Your b variable
is essentially pointing to random memory.
If you are going to use the wrappers generated by #import, prefer the wrapper
types to the raw automation types, and do something like this:
_bstr_t b = m_pdoc->Getxml();
// b can now be used safely until it goes out of scope
_bstr_t deallocates the contained string in its destructor, so you generally
don't need to worry about any deallocation.
--
Best Regards,
Kim Gräsma
Abubakar - 29 Aug 2006 11:03 GMT
> Actually, I believe your code is incorrect. IXMLDOMDocumentPtr is a compiler-generated
you are right but in my case it was working just fine.
> If you are going to use the wrappers generated by #import, prefer the wrapper
> types to the raw automation types, and do something like this:
[quoted text clipped - 4 lines]
> _bstr_t deallocates the contained string in its destructor, so you generally
> don't need to worry about any deallocation.
Understood.
Thanks.
-ab.
> Hi Abubakar,
>
[quoted text clipped - 24 lines]
> Best Regards,
> Kim Gräsman