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äsman