GetSystemPath 或 SHGetSpecialFolderPath - 我对 CommonDocs 文件夹使用哪一个?
(Delphi 2006) 我正在获取通用文档文件夹,以便在应用程序启动期间创建另一个文件夹。这一直工作正常 - 它总是返回:
C:\Documents and Settings\All Users\Documents\
但我刚刚收到来自西班牙用户的错误报告,其中包含一个启动日志,显示应用程序正在尝试创建:
MyApp\
而不是:
C:\Documents and Settings\All Users\Documents\MyApp\
即公共文档文件夹字符串为空。得到这个的代码是:
function GetCommonDocumentsFolder : TFilename ;
begin
Result := GetSystemPath (CSIDL_COMMON_DOCUMENTS) ;
end ;
我在研究这个问题时还注意到还有一个系统调用:
SHGetSpecialFolderPath
我应该使用哪个? GetSystemPath (CSIDL_COMMON_DOCUMENTS) 对我有用(至少在英语区域设置 Windows XP 中)。
所以有两个问题确实可能相关:
- 为什么 GetSystemPath (CSIDL_COMMON_DOCUMENTS) 返回 null?
- 我实际上应该使用 SHGetSpecialFolderPath 吗?
(天哪,这很难找到标签)
神秘的 GetSystemPath 的来源:
function GetSystemPath (Folder: Integer) : TFilename ;
{ Call this function with one of the constants declared above. }
var
PIDL : PItemIDList ;
Path : LPSTR ;
AMalloc : IMalloc ;
begin
Path := StrAlloc (MAX_PATH) ;
SHGetSpecialFolderLocation (Application.Handle, Folder, PIDL) ;
if SHGetPathFromIDList (PIDL, Path) then
begin
Result := IncludeTrailingPathDelimiter (Path) ;
end
else
begin
Result := '' ;
end ; ;
SHGetMalloc(AMalloc) ;
AMalloc.Free (PIDL) ;
StrDispose (Path) ;
end;
(Delphi 2006) I am getting the Common documents folder in order to create another folder off it during my app startup. This has been working fine - it always returns:
C:\Documents and Settings\All Users\Documents\
but I have just received a bug report from a Spanish user that includes a startup log that shows the app was trying to create:
MyApp\
instead of:
C:\Documents and Settings\All Users\Documents\MyApp\
i.e. the common docs folder string was empty. The code to get this is:
function GetCommonDocumentsFolder : TFilename ;
begin
Result := GetSystemPath (CSIDL_COMMON_DOCUMENTS) ;
end ;
I also note in my researching of this problem that there is also a system call:
SHGetSpecialFolderPath
Which one should I be using? GetSystemPath (CSIDL_COMMON_DOCUMENTS) has worked for me (at least in English locale Windows XP).
So 2 questions really, possibly related:
- why does GetSystemPath (CSIDL_COMMON_DOCUMENTS) return null?
- should I in fact be using SHGetSpecialFolderPath ?
(boy, this was a hard one to find tags for)
Source for the mysterious GetSystemPath:
function GetSystemPath (Folder: Integer) : TFilename ;
{ Call this function with one of the constants declared above. }
var
PIDL : PItemIDList ;
Path : LPSTR ;
AMalloc : IMalloc ;
begin
Path := StrAlloc (MAX_PATH) ;
SHGetSpecialFolderLocation (Application.Handle, Folder, PIDL) ;
if SHGetPathFromIDList (PIDL, Path) then
begin
Result := IncludeTrailingPathDelimiter (Path) ;
end
else
begin
Result := '' ;
end ; ;
SHGetMalloc(AMalloc) ;
AMalloc.Free (PIDL) ;
StrDispose (Path) ;
end;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该调用
SHGetSpecialFolderPath
当您想知道 CSIDL。我不知道
GetSpecialFolderPath
是什么,我在 Delphi 中找不到它。您是指SHGetSpecialFolderPath
吗?我也找不到GetSystemPath
,但这并没有改变我的答案!You should call
SHGetSpecialFolderPath
when you want to know the path corresponding to a CSIDL.I don't know what
GetSpecialFolderPath
is, I can't find it in my Delphi. Did you meanSHGetSpecialFolderPath
? I also can't findGetSystemPath
, but that doesn't change my answer!