Article View: borland.public.cppbuilder.nativeapi
Article #476Re: Cleaning up after using GetDisplayNameOf()
From: Remy Lebeau (TeamB)
Date: Thu, 13 Mar 2008 16:45
Date: Thu, 13 Mar 2008 16:45
73 lines
3028 bytes
3028 bytes
"Kris" <x@x.com> wrote in message news:47d8ec90$1@newsgroups.borland.com...
> Do I have to take care of freeing that memory
Yes.
> is someone else taking care of freeing the STRRET.pOleStr
> (e.g. pDesktopFolder) ?
No.
> Probably safe to assume STRRET_WSTR is set in this specific case
> So simply use the pOleStr member without any additional checks
You cannot assume that. You need to look at the STRRET's uType parameter to
know exactly how to interpret the STRRET's contents properly, for example:
switch( sName.uType )
{
case STRRET_CSTR
DEBUG("DisplayNameof(CSIDL_PERSONAL)=[%s]", sName.cStr);
break;
case STRRET_OFFSET:
{
char *pName = (char*)(((LPBYTE)pidl) + sName.uOffset);
DEBUG("DisplayNameof(CSIDL_PERSONAL)=[%s]", pName);
break;
}
case STRRET_WSTR:
{
// assuming DEBUG() is based on printf() or similar function...
DEBUG("DisplayNameof(CSIDL_PERSONAL)=[%ls]", sName.pOleStr);
CoTaskMemFree(sName.pOleStr);
break;
}
}
Alternatively, you can use one of the StrRetTo...() functions instead, which
also handle freeing the STRRET_WSTR memory for you, ie:
TCHAR szBuf[MAX_PATH+1] = {0};
StrRetToBuf(&sName, pidl, szBuf, MAX_PATH+1);
#ifdef UNICODE
DEBUG("DisplayNameof(CSIDL_PERSONAL)=[%ls]", szBuf);
#else
DEBUG("DisplayNameof(CSIDL_PERSONAL)=[%s]", szBuf);
#endif
Or:
LPTSTR pName;
StrRetToStr(&sName, pidl, &pName);
#ifdef UNICODE
DEBUG("DisplayNameof(CSIDL_PERSONAL)=[%ls]", szBuf);
#else
DEBUG("DisplayNameof(CSIDL_PERSONAL)=[%s]", szBuf);
#endif
CoTaskMemFree(pName);
Or:
WideString wName;
StrRetToBSTR(&sName, pidl, &wName);
DEBUG("DisplayNameof(CSIDL_PERSONAL)=[%ls]", wName.c_bstr());
Gambit
Technical Details
Message-ID:
<47d95ab1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeed.freenet.de!news.albasani.net!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<47d8ec90$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b8d31d04a1ebb7b9 X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <47d8ec90$1@newsgroups.borland.com> Subject: Re: Cleaning up after using GetDisplayNameOf() Date: Thu, 13 Mar 2008 09:45:53 -0700 Lines: 75 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <47d95ab1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1205426865 207.178.157.90 (13 Mar 2008 09:47:45 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeed.freenet.de!news.albasani.net!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail X-Original-Bytes: 2812