【发布时间】:2016-03-08 04:01:08
【问题描述】:
我正在为 Windows 7 及更高版本编写 C++ 桌面应用程序。
我想获取 AppData/Roaming 文件夹的路径,所以我使用 SHGetKnownFolderPath:
#include "stdafx.h"
#include <windows.h>
#include <ShlObj.h>
void hello()
{
LPWSTR roamingPath;
SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &roamingPath);
问题:构建失败并出现identifier "SHGetKnownFolderPath" is undefined,这很奇怪,因为我认为我包含了正确的标题。
注意事项:
- Visual Studio 2015 告诉我我的编译选项是
/Yu"stdafx.h" /GS /analyze- /W3 /Zc:wchar_t /ZI /Gm /Od /Fd"Debug\vc140.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_WINDOWS" /D "_DEBUG" /D "_USRDLL" /D "_WINDLL" /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\OverlayIcon.pch"。 - 与 Error: identifier :"SHGetKnownFolderPath" is unidentified 不同,问题在于提问者的目标不仅仅是桌面。
【问题讨论】:
-
您的 stdafx.h 标头中的 target platform macros 可能对这个问题很重要,因为它们的值表明在通过标头编译时公开了哪些功能。可能希望在您的问题中包含这些内容。
-
@WhozCraig:添加! StackOverflow 语法问题:-/
-
在您更新帖子后,它现在应该至少编译源代码。顺便说一句,您在项目中拥有该 stdafx.h 标头。不只是将值更改为正确的目标没有什么意义,因为它无论如何都包含在您的所有翻译单元中。
标签: c++ visual-studio-2015 header-files appdata shell32.dll