🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #474

Cleaning up after using GetDisplayNameOf()

#474
From: Kris
Date: Thu, 13 Mar 2008 08:56
47 lines
2312 bytes
Hi,

I'm using GetDisplayNameOf() to obtain the (localized) display name of 
the MyDocuments folder (i.e. CSIDL_PERSONAL).

This was somewhat confusing to implement, but I managed to get it 
working properly. However, I am unsure if I'm doing a proper clean-up 
after I'm finished ?

I'm especially concerned about the STRRET info at 
http://msdn2.microsoft.com/en-us/library/bb759820(VS.85).aspx that states:

pOleStr:
A pointer to the string. This memory must be allocated with 
CoTaskMemAlloc. It is the calling application's responsibility to free 
this memory with CoTaskMemFree when it is no longer needed.

Do I have to take care of freeing that memory, or is someone else taking 
care of freeing the STRRET.pOleStr (e.g. pDesktopFolder) ?

Please feel free to mention any other (clean-up) issues that you might 
notice with the code sample below.

Thanks,

Kris

CoInitialize(0) ;
LPITEMIDLIST pidl;
STRRET sName;
LPSHELLFOLDER pDesktopFolder;
if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,CSIDL_PERSONAL,&pidl)))
{
if(SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder)))
{
if(SUCCEEDED(pDesktopFolder->GetDisplayNameOf(pidl,SHGDN_INFOLDER,&sName)))
{
// Probably safe to assume STRRET_WSTR is set in this specific case
// So simply use the pOleStr member without any additional checks
WideString DisplayName=sName.pOleStr;
DEBUG("DisplayNameof(CSIDL_PERSONAL)=[%s]",String(DisplayName).c_str());
}
pDesktopFolder->Release();
}
CoTaskMemFree((void*)pidl);
}
CoUninitialize();
Technical Details
Message-ID: <47d8ec90$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b8d31d04a1ebb7b9,start
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Thu, 13 Mar 2008 09:56:06 +0100
From: Kris <x@x.com>
User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Cleaning up after using GetDisplayNameOf()
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 81.242.6.168
Message-ID: <47d8ec90$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1205398672 81.242.6.168 (13 Mar 2008 01:57:52 -0700)
Lines: 47
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail