title: GetSystemPath or SHGetSpecialFolderPath - Which do I use for CommonDocs folder?
body: <p>(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:</p>
  
  <pre><code>C:\Documents and Settings\All Users\Documents\
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>MyApp\  
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>C:\Documents and Settings\All Users\Documents\MyApp\ 
  </code></pre>
  
  <p>i.e. the common docs folder string was empty.  The code to get this is:</p>
  
  <pre><code>function GetCommonDocumentsFolder : TFilename ;
  
  begin
  Result := GetSystemPath (CSIDL_COMMON_DOCUMENTS) ;
  end ;
  </code></pre>
  
  <p>I also note in my researching of this problem that there is also a system call:</p>
  
  <pre><code>SHGetSpecialFolderPath 
  </code></pre>
  
  <p>Which one should I be using?  GetSystemPath (CSIDL_COMMON_DOCUMENTS) has worked for me (at least in English locale Windows XP).</p>
  
  <p>So 2 questions really, possibly related:</p>
  
  <ul>
  <li>why does GetSystemPath (CSIDL_COMMON_DOCUMENTS) return null?</li>
  <li>should I in fact be using SHGetSpecialFolderPath ?</li>
  </ul>
  
  <p>(boy, this was a hard one to find tags for)</p>
  
  <p>Source for the mysterious GetSystemPath:</p>
  
  <pre><code>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;
  </code></pre>