Please don’t hard-code “C:\Program Files”, as the
directory has different names depending upon the
region that the OS is configure for. I know that in
the German version of windows it is called something
else.
In my own project I have the following source file.
Notice that I can’t include the normal headers for my
project, as the shell library includes some crap that
breaks my builds. Anyway, here is a starting point:
(plus, at work, our “home” folder is really a network
drive. It follows us around where ever we go.
Hard-coding a data path to “C:” would not work in this
environment).
/* $Id: win32funcs.cc 16 2004-03-27 16:21:01Z djenkins
$ */
/* This is compiled seperately, and without including
"include/platform.h"
because including ‘Shlobj.h’ causes compiler errors
if included with
’platform.h’. */
#if !defined(WIN32)
#error “Only compile this under Win32!”
#endif
#define STRICT
#include <windows.h>
#include <Shlobj.h>
#include
bool Win32_GetDocPath(std::string &sDocPath)
{
IShellFolder *folder = 0;
ITEMIDLIST *itemidlistptr = 0;
IMalloc *alloc = 0;
char szDocPath[MAX_PATH];
SHGetSpecialFolderLocation(0, CSIDL_PERSONAL,
&itemidlistptr);
SHGetPathFromIDList(itemidlistptr, szDocPath);
if (!SUCCEEDED(SHGetMalloc(&alloc)))
{
return false;
}
alloc->Free(itemidlistptr);
sDocPath = szDocPath;
return true;
}=====
Dennis Jenkins