![](https://secure.gravatar.com/avatar/82c0f6eed0ee59676eb45aadd66dac57.jpg?s=120&d=mm&r=g)
Jon A. Cruz wrote:
On May 6, 2006, at 2:16 AM, Jasper van de Gronde wrote:
How about using SHGetSpecialFolderPath? Should work on pretty much any Windows system and is reasonably easy to use.
Example usage (prints the location of the My Documents directory for the current user):
#define _WIN32_IE 0x0400
Nope!
fails on Windows 95 and Windows NT 4.0 that don't have extra newer stuff installed.
:-)
(notice that say I have version such-and-such of Internet Explorer or later)
For reference, wxWidgets uses SHGetFolderPath followed by SHGetSpecialFolderPath, if they both fail (or if they don't exist) it uses SHGetSpecialFolderLocation, which is apparently available pretty much everywhere. I'm not sure why they first try SHGetSpecialFolderPath, as far as I can see it mostly functions as a wrapper for SHGetSpecialFolderLocation. In any case, the following should also work on Windows NT 4 and Windows 95 (probably without too much extra installed, as there is no IF _WIN32_IE >= ... around the function prototypes in shlobj.h):
#include <shlobj.h> #include <stdio.h>
int main() { char path[MAX_PATH]; LPITEMIDLIST itemIdList; SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &itemIdList); SHGetPathFromIDList(itemIdList, path);
IMalloc* allocPtr; SHGetMalloc(&allocPtr); allocPtr->Free(itemIdList); allocPtr->Release();
printf("My docs: %s\n", path); return 0; }