使用c ++获取%APPDATA%路径 [英] get %APPDATA% path using c++

查看:3900
本文介绍了使用c ++获取%APPDATA%路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,伙计们,我想找到%APPDATA%文件夹的路径。

Hey guys, i want to get the path to the %APPDATA% folder.

在win 2000& xp它在:C:\Documents和Settings \user name\Application Data

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

在vista& win7它在:C:\Users \user name\AppData\Roaming

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

我知道有一个函数 SHGetSpecialFolderPath 但它检索BOOL
,我想获取路径作为字符串。

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

可以帮助一些吗?

推荐答案

SHGetSpecialFolderPath() ,命名为 lpszPath ,标记为 __ out

应该这样做:

// 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;

注意:我几年来没有做过任何Win API工作。很可能有人来很快地指出我在哪里吹。

Note: I haven't done any Win API work in years. Very likely someone comes along shortly pointing out where I blew it.

这篇关于使用c ++获取%APPDATA%路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆