Article View: borland.public.cppbuilder.nativeapi
Article #11931Re: Finding the name of the Program Files directory
From: Fernando
Date: Wed, 07 Jan 2004 16:00
Date: Wed, 07 Jan 2004 16:00
45 lines
2452 bytes
2452 bytes
On Wed, 7 Jan 2004 15:36:15 +0100, "PaoloItaly"
<paolot@FAKETHESPAMMERsirius-es.it> wrote:
>> How can I find the name of the 'program files' directory?
>
>Look at SHGetSpecialFolderPath()
>
I couldn't find that function, but did find SHGetSpecilaFolderLocation().
However, when I try to include shlobj.h in order to use it, I get a compiler
error.
[C++ Error] shobjidl.h(2193): E2238 Multiple declaration for 'FOLDERSETTINGS'
[C++ Error] shobjidl.h(8095): E2238 Multiple declaration for 'DESKBANDINFO'
[C++ Error] shlobj.h(1422): E2238 Multiple declaration for 'FVSHOWINFO'
[C++ Error] shlobj.h(3457): E2238 Multiple declaration for 'SHELLFLAGSTATE'
This is the code:
---------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include <shlobj.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
AnsiString GetSpecialFolderPath(int nFolder)
{
AnsiString retPath;
char szPath[_MAX_PATH];
LPITEMIDLIST pidl;
HRESULT hr = SHGetSpecialFolderLocation(NULL, nFolder, &pidl);
if (hr==NOERROR && SHGetPathFromIDList(pidl, szPath))
retPath=szPath;
// Allocate a pointer to an IMalloc interface
LPMALLOC pMalloc;
// Get the address of our task allocator's IMalloc interface
hr = SHGetMalloc(&pMalloc);
// Free the item ID list allocated by SHGetSpecialFolderLocation
pMalloc->Free(pidl);
// Free our task allocator
pMalloc->Release();
return retPath;
}
Technical Details
Message-ID:
<o5bovvo2ruigqkkvpvh35h8p4g7479hm54@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<8rtnvvs0ekdahr4ti11p9tbhpvvek5taju@4ax.com> <3ffc198e$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,8234f234f0df84a1 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-07 08:09:46 PST From: Fernando <frr@easyjob.net> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Finding the name of the Program Files directory Date: Wed, 07 Jan 2004 17:00:56 +0100 Message-ID: <o5bovvo2ruigqkkvpvh35h8p4g7479hm54@4ax.com> References: <8rtnvvs0ekdahr4ti11p9tbhpvvek5taju@4ax.com> <3ffc198e$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.9/32.560 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 217.127.66.80 X-Trace: newsgroups.borland.com 1073491256 217.127.66.80 (7 Jan 2004 08:00:56 -0700) Lines: 45 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail