Hello neuronic,
I see that you figured out your problem, but when I tried it I could not duplicate the error.
After look into your code I did find this:
https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderpatha?redirectedfrom=MSDN&f1url=%3FappId%3DDev15IDEF1%26l%3DEN-US%26k%3Dk(SHLOBJ_CORE%252FSHGetFolderPath);k(SHGetFolderPath);k(DevLang-C%252B%252B);k(TargetOS-Windows)%26rd%3Dtrue
And at the beginning it says "
Deprecated. Gets the path of a folder identified by a CSIDL value."
Then it did not give me the answer I was hoping for.
I made some changes to your code so I could use it with the 2014 standards:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
//#include <filesystem>
#include <experimental/filesystem>
#include <shlobj.h>
//#pragma comment(lib, "shell32.lib")
//namespace fs = std::filesystem;
namespace fs = std::experimental::filesystem;
int main()
{
int lineNum{ 1 };
char programx86[MAX_PATH]/*{ "F:/VS 2017" }*/;
HRESULT result = SHGetFolderPath(NULL, CSIDL_PROGRAM_FILESX86, NULL, SHGFP_TYPE_CURRENT, programx86);
for (auto& p : fs::recursive_directory_iterator(programx86))
{
//if (lineNum == 21)break;
std::cout << lineNum++ << ") " << p.path().u8string() << std::endl;
}
return 0; // <--- Not required, but makes a good break point.
}
|
Line 7 may be included even if you do not. With MSVS 2017 it made no difference.
The if statement in the for loop I used to see how it worded because "C:\Program Files (x86)" listed 121,322 files. Then again my "C:\Program Files (x86)\Google\CrashReports" is an empty sub-directory, so I do not know if it would be a problem.
In line 16 I found that "CHAR" is not needed, but works. As you see I just used "char". If you remove the block comments you can initialize the variable to whatever path you want. I would also consider changing the name to "path" or initialPath" to better describe its use.
Since it is deprecated I put a comment on line 17 and it worked fine.
See what you think about it. Switch some of the comments and you can use it with the 2017 standards.
Andy