SHGetKnownFolderPath for x64 Program Files under WoW64 fails. RRS feed

  • Question

  • Calling SHGetKnownFolderPath with the parameter of FOLDERID_ProgramFilesX64 fails with ERROR_FILE_NOT_FOUND when I call it from a 32-bit app. This is contrary to the documentation in the remarks section of: http://msdn2.microsoft.com/en-us/library/bb762584(VS.85).aspx, which clearly states that it's valid to call the function with that parameter from a 32-bit app on a 64-bit OS.


    Sample code:

    Code Snippet

    // Compile with: cl /EHsc knownfolder.cpp /link shell32.lib

    #include <shlobj.h>
    #include <iostream>
    using std::cout;

    int main()
     wchar_t *path;
     cout << SHGetKnownFolderPath(FOLDERID_ProgramFilesX64, 0, NULL, &path);



    Compile this with both the x32 and x64 compilers:


    • The x64 compiler will produce a binary which succeeds (ie. prints zero), and path will have been filled with (by default) "c:\Program Files".
    • The x32 compiler will produce a binary which fails with ERROR_FILE_NOT_FOUND (-2147024894 according to the code above) (and path will not be set).
      • This happens even with combinations of the KF_FLAG_CREATE and KF_FLAG_DONT_VERIFY as well as 0 (as above).
      • It happens as Administrator.
      • It happens even if you call Wow64DisableWow64FsRedirection (successfully) before this call.


    Saturday, April 12, 2008 2:38 AM

All replies