Article View: borland.public.cppbuilder.nativeapi
Article #11933Re: Finding the name of the Program Files directory
From: Remy Lebeau (TeamB)
Date: Wed, 07 Jan 2004 18:54
Date: Wed, 07 Jan 2004 18:54
59 lines
2772 bytes
2772 bytes
"Fernando" <frr@easyjob.net> wrote in message
news:o5bovvo2ruigqkkvpvh35h8p4g7479hm54@4ax.com...
> I couldn't find that function
It is available in every version of BCB since at least BCB3. It is declared
in shlobj.h.
> but did find SHGetSpecilaFolderLocation().
That will work as well. SHGetSpecialFolderPath() is merely a wrapper for
SHGetSpecialFolderLocation() and SHGetPathFromIDList().
> However, when I try to include shlobj.h in order to use it, I get a
compiler
> error.
You need to add NO_WIN32_LEAN_AND_MEAN to the Conditionals list in your
Project Options.
> #include <vcl.h>
> #include <windows.h>
> #include <shlobj.h>
> #pragma hdrstop
You should not include the Windows headers before the #pragma hdrstop
statement. That prevents the project from being able to use the VCL's
default precompiled headers correctly (if you have PCH enabled, that is).
Include them after the statement instead:
#include <vcl.h>
#pragma hdrstop
#include <windows.h>
#include <shlobj.h>
> char szPath[_MAX_PATH];
That should be using MAX_PATH, not _MAX_PATH (notice the preceeding
underscore). Also, it is always a good idea to allocate an extra space for
a null terminator in case a path happens to actually be MAX_PATH in length,
and also to zero out the buffer content before using using it. The
simpliest way to do that is as follows:
char szPath[MAX_PATH+1] = {0};
> // Allocate a pointer to an IMalloc interface
> LPMALLOC pMalloc;
Just an FYI, you can use the CoTaskMemFree() function, which uses IMalloc
internally:
CoTaskMemFree(pidl);
Alternatively, The Win32 API does have SHFree() and ILFree() functions that
could be used as well.
Gambit
Technical Details
Message-ID:
<3ffc546d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<8rtnvvs0ekdahr4ti11p9tbhpvvek5taju@4ax.com> <3ffc198e$1@newsgroups.borland.com> <o5bovvo2ruigqkkvpvh35h8p4g7479hm54@4ax.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 11:10:31 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <8rtnvvs0ekdahr4ti11p9tbhpvvek5taju@4ax.com> <3ffc198e$1@newsgroups.borland.com> <o5bovvo2ruigqkkvpvh35h8p4g7479hm54@4ax.com> Subject: Re: Finding the name of the Program Files directory Date: Wed, 7 Jan 2004 10:54:08 -0800 Lines: 61 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: 67.22.138.253 Message-ID: <3ffc546d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1073501293 67.22.138.253 (7 Jan 2004 10:48:13 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail