(Delphi 2006)アプリの起動時に別のフォルダーを作成するために、Commondocumentsフォルダーを取得しています。これは正常に機能しています-常に次を返します:
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では)。
したがって、2つの質問が実際に関連している可能性があります。
- 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;