Unable to call SHGetKnownFolderPath() even with #include <Shlobj.h> and #pragma comment (lib, “Shell32.lib”)

断了今生、忘了曾经 提交于 2019-12-01 21:52:59

问题


(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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!