Get% APPDATA% path using C ++

Hi guys, I want to get the path to the% APPDATA% folder.

in win 2000 and xp in: C: \ Documents and Settings \ username \ Application Data p>

in vista and win7 in: C: \ Users \ username \ AppData \ Roaming

I know that there is a SHGetSpecialFolderPath function, but it retrieves BOOL and I want to get the path as a string.

Can anyone help?

+4
source share
1 answer

The third parameter, SHGetSpecialFolderPath() , called lpszPath , is marked as __out .

Something like this should do:

 // Beware, brain-compiled code ahead! wchar_t buffer[MAX_PATH]; BOOL result = SHGetSpecialFolderPath( hWnd , buffer , CSIDL_LOCAL_APPDATA , false ); if(!result) throw "You'll need error handling here!"; std::wcout << buffer; 

Note. I have not worked for several years. Most likely, someone comes, briefly indicating where I blew him up.

+7
source

Source: https://habr.com/ru/post/1332882/


All Articles