如何获取系统文件夹路径(C:\\ WINDOWS C:\\ Program Files文件)在Windows中使用C ++? [英] How To Get System Folder Path(C:\Windows C:\Program Files) in Windows using C++?
问题描述
我编程在C ++ MFC,
I am programming in c++ MFC,
我想获得C:\\ WINDOWSC:\\ Program Files文件文件夹路径。
I want to get "C:\windows" "c:\program files" folder path.
有时,用户可以在其他文件夹设置窗口,如C:\\ windows0。
是否有任何的API来获取窗口和程序文件路径的绝对路径?
Sometimes user may setup windows in other folder such as c:\windows0.
Is there any API to get absolute path of the windows and program files path?
非常感谢!
推荐答案
使用的Win32 API>
Using Win32 API>
有关Windows文件夹:
For the Windows folder:
TCHAR windir[MAX_PATH];
GetWindowsDirectory(windir, MAX_PATH);
有关程序文件:
TCHAR pf[MAX_PATH];
SHGetSpecialFolderPath(
0,
pf,
CSIDL_PROGRAM_FILES,
FALSE );
其中, MAX_PATH
来自Windows头,并保证缓冲区是最长的(非UNC)路径足够长的时间。
Where MAX_PATH
comes from the Windows headers and will guarantee the buffer is long enough for the longest (non-UNC) path.
另外,还要注意 SHGetSpecialFolderPath
只需从该更换的第三个参数任何的list 。
Also, note that SHGetSpecialFolderPath
can be used to retrieve other "special" folder including the Windows folder just by replacing the third parameter to any from this list.
这篇关于如何获取系统文件夹路径(C:\\ WINDOWS C:\\ Program Files文件)在Windows中使用C ++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!