问题
(Visual Studio 2010 / Visual C++ / Windows 7)
example.cpp:
#include <Shlobj.h>
#pragma comment (lib, "Shell32.lib")
...
void example()
{
SHGetKnownFolderPath(...) // undefined
}
I'm doing everything according to documentation and what I see in other threads, but it still doesn't work.
回答1:
I had exactly the same problem. Another project with the same code and ancillary files (but different includes) was working.
Putting #include <Shlobj.h>
at the top of the file solved the problem.
It might not be replicable though, as it should have worked without doing that. Probably another Visual Studio bug.
回答2:
Try putting following statement before all includes:
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
Since the documentation says it needs Vista/2008 minimum.
来源:https://stackoverflow.com/questions/22379195/unable-to-call-shgetknownfolderpath-even-with-include-shlobj-h-and-pragma