Re: CString::AllocSysString() needs to be free'd?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jagadeesh VN (jagadeeshvn_at_hotmail.com)
Date: 02/13/04


Date: Fri, 13 Feb 2004 18:31:48 +0530

This actually depends upon the object you are using it with. In most cases,
the caller of the function is responsible for freeing it. Otherwise, the
object has no way of knowing whether you are finished with the BSTR object
or not.

So, you can use ::SysFreeString().

I always prefer using CComBSTR instead of this approach.

Cheers
Jagadeesh

"Anders Eriksson" <anders.eriksson@morateknikutveckling.se> wrote in message
news:kddxce06z30g.dlg@morateknikutveckling.se...
> Hello!
>
> I'm using VC++ 7.0 (.net 2002) and MFC.
>
> I have a function (foo) that uses a CString variable (strCommand) as a
> parameter. foo is accessing a database via ADO. Among the code is this:
>
> pCommand->put_CommandText(strCommand.AllocSysString());
>
>
> Do I need to free the memory allocated to string or will it do so
> automatically?
>
> // Anders
>
> Crossposted to:
microsoft.public.dotnet.languages.vc,microsoft.public.vc.language,microsoft.
public.vc.mfc
> Replies will go to: microsoft.public.dotnet.languages.vc



Relevant Pages