GetSystemPath 或 SHGetSpecialFolderPath - 我对 CommonDocs 文件夹使用哪一个?

发布于 2024-10-21 06:10:58 字数 1412 浏览 6 评论 0原文

(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷→糖丶微凉 2024-10-28 06:10:58

您应该调用 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 mean SHGetSpecialFolderPath? I also can't find GetSystemPath, but that doesn't change my answer!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文