🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: SpecialFolderLocation!

#13882
From: Remy Lebeau (TeamB)
Date: Sun, 14 Sep 2003 21:53
31 lines
1881 bytes
"Safari" <Safari@alloymail.com> wrote in message
news:3F649347.7090500@alloymail.com...

> AnsiString __fastcall GetPaths(int Path)
> {
>     PItemIDList idList;
>     char idPath[MAX_PATH];
>     SHGetSpecialFolderLocation(0, Path, &idList);
>     SHGetPathFromIDList(idList, idPath);
>     return String(idPath);
> }

I should point out that there are two other problems with this code:

1) your buffer should be MAX_PATH+1, in case SHGetPathFromIDList() returns a
path that is exactly MAX_PATH in length, thus losing the null terminator

2) you have a memory leak as you are never freeing the ITEMIDLIST that
SHGetSpecialFolderLocation() returns.  You must use CoTaskMemFree() or
IMalloc::Free() in order to free the memory correctly *before* you return
from the function.


Gambit


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/03
Technical Details
Message-ID: <3f64e30b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3F649347.7090500@alloymail.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,64d61a6d0b62f704
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-09-14 14:56:47 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3F649347.7090500@alloymail.com>
Subject: Re: SpecialFolderLocation!
Date: Sun, 14 Sep 2003 14:53:01 -0700
Lines: 33
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3f64e30b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1063576331 207.175.226.26 (14 Sep 2003 14:52:11 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail