title: SHGetFolderPath doesn't work for me
body: <p>I have this function:</p>
  
  <pre><code>function GetProfilePath: string;
  const
    SHGFP_TYPE_CURRENT = 0;
  var
    hToken: THandle;
    ProfilePath: packed array[ 0..MAX_PATH ] of Char;
  begin
    ZeroMemory(@ProfilePath[0], SizeOf(ProfilePath));
    OpenProcessToken( GetCurrentProcess, TOKEN_QUERY, hToken );
    SHGetFolderPath( 0, CSIDL_APPDATA, hToken , SHGFP_TYPE_CURRENT, @ProfilePath[ 0 ] );
    CloseHandle( hToken );
    Result := ProfilePath;
  end;
  </code></pre>
  
  <p>SHGetFolderPath returns E_FAIL (0x80004005) and an empty ProfilePath buffer. MSDN says that E_FAIL means "The CSIDL in nFolder is valid, but the folder does not exist". But the folder does exist, I'm pretty sure. When I'm creating a simple test application and running the same code, it works well.</p>
  
  <p>What might be wrong with that?</p>
  
  <p><strong>update</strong>:
  I found that my application doesn't work well when running under Delphi. When I run it separately, all is OK. </p>
  
  <p>Thanks,
  Roman</p>