开发者

get %APPDATA% path using c++

开发者 https://www.devze.com 2023-01-31 09:06 出处:网络
I want to get the path to the %APPDA开发者_开发技巧TA% folder. In win 2000 & xp it\'s in: C:\\Documents and Settings\\user name\\Application Data

I want to get the path to the %APPDA开发者_开发技巧TA% folder.

In win 2000 & xp it's in: C:\Documents and Settings\user name\Application Data

In vista & win7 it's in: C:\Users\user name\AppData\Roaming

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


The third parameter of SHGetSpecialFolderPath(), named 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 haven't done any Win API work in years. Very likely someone comes along shortly pointing out where I blew it.

0

精彩评论

暂无评论...
验证码 换一张
取 消