Click to See Complete Forum and Search --> : Finding exact path of 'My documents' folder


leojose
September 9th, 2005, 08:44 AM
Hi all,

This is what I do to find the exact path of 'My documents' folder on any XP machine. But it fails on some XP systems.


CRegKey regKey;

regKey.Open(HKEY_CURRENT_USER,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders")
regKey.QueryValue(NULL,"Personal",&dwValData);
sMyDocumentsPath = (char *)malloc(dwValData);
regKey.QueryValue(sMyDocumentsPath,"Personal",&dwValData)


Can there be any flaws in the above technique?

Eli Gassert
September 9th, 2005, 09:04 AM
SHGetSpecialFolderPath is the function you wanna use:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shgetspecialfolderpath.asp

The list of CLSIDs:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp

Edit: for examples of how to use it... use google or the code guru forum. There are quite a few articles (found with both search engines) that will help you use this function. But it's pretty easy to use. Chances are you'll pass NULL for the first param, and the rest are self explanatory (hopefully :))