English 中文(简体)
C++ WindSDK 标题编辑错误
原标题:C++ WinSDK header compilation error

我试图在 Windows 7 中编译2010 视觉工作室的程序。 我正获取一个编译错误 < strong> C2061: 语法错误: 在标记行的 Windows header shlobj.h 中, 识别符号 I known_ FOLDER_ FLAG :

#if (NTDDI_VERSION >= NTDDI_VISTA)

typedef enum
{
    KF_FLAG_DEFAULT         = 0x00000000,
    KF_FLAG_CREATE          = 0x00008000,
    KF_FLAG_DONT_VERIFY     = 0x00004000,
    KF_FLAG_DONT_UNEXPAND   = 0x00002000,
    KF_FLAG_NO_ALIAS        = 0x00001000,
    KF_FLAG_INIT            = 0x00000800,
    KF_FLAG_DEFAULT_PATH    = 0x00000400,
    KF_FLAG_NOT_PARENT_RELATIVE = 0x00000200,
    KF_FLAG_SIMPLE_IDLIST   = 0x00000100,
    KF_FLAG_ALIAS_ONLY      = 0x80000000,
} KNOWN_FOLDER_FLAG;


DEFINE_ENUM_FLAG_OPERATORS(KNOWN_FOLDER_FLAG);

STDAPI SHGetKnownFolderIDList(__in REFKNOWNFOLDERID rfid,
                              __in DWORD /* KNOWN_FOLDER_FLAG */ dwFlags,
                              __in_opt HANDLE hToken,
                              __deref_out PIDLIST_ABSOLUTE *ppidl);

STDAPI SHSetKnownFolderPath(__in REFKNOWNFOLDERID rfid,
                            __in DWORD /* KNOWN_FOLDER_FLAG */ dwFlags,
                            __in_opt HANDLE hToken,
                            __in PCWSTR pszPath);

STDAPI SHGetKnownFolderPath(__in REFKNOWNFOLDERID rfid,
                            __in DWORD /* KNOWN_FOLDER_FLAG */ dwFlags,
                            __in_opt HANDLE hToken,
                            __deref_out PWSTR *ppszPath);

#endif  // NTDDI_VISTA

#if (NTDDI_VERSION >= NTDDI_WIN7)

STDAPI SHGetKnownFolderItem(__in REFKNOWNFOLDERID rfid,
                            __in KNOWN_FOLDER_FLAG flags, <<<ERROR AT THIS LINE
                            __in_opt HANDLE hToken,
                            __in REFIID riid,
                            __deref_out void **ppv);
#endif // NTDDI_WIN7

在我的程序中,版本宏被定义为 flows 。

#define NTDDI_VERSION NTDDI_WINXP

为何它不汇编成册?

在我看来,我得到的错误部分 绝对不能被汇编起来, 但它还是有的。

最佳回答

只有一个逻辑结论:由于某种原因,当该页眉编译时, NTDDI_VERSION 的扩展不是你想的那样。

尝试通过搜索 来排除故障, 并对您的工程进行清洁构建( 如果您使用预编译信头, 可能会相关 ) 。

问题回答

EDIT: My answer was written without scrolling down the code sample... Have you confirmed that the error is coming from the line that defines SHGetKnownFolderItem? When I run into these kinds of problems, I usually create a preprocessor output file for your file and confirm that the error is actually coming from where you expect. It s possible there is some other piece of code which wasn t properly NTDDI_VERSION guarded.

创建 SDK 窗口信头是为了让您为特定版本的 Windows 建立应用程序 。

在此情况下, 您要求构建您的 Windows XP 应用程序( 将 NTDDI_ VerSION 设置为 NTDDI_ WINXP ) 。 很好 。 但是您正在尝试使用 Windows Vista 中引入的 enum (KNOWN_ FOLDER_ FLAG) 。

您需要做出选择: 使用 Windows APIs 的 Windows Vista 版本构建您的应用程序( 将 NTDDI_ VERSION 设置为 NTDDI_ VISTA), 或者找到另外一种分隔 Windows Vista 特定功能的方法 。

有几种方法可以做到这一点。 第一个( 最棘手的) 是用 Vista 信头构建您的应用程序, 然后小心避免在 XP 上使用 Vista 专用功能 。 或者, 您可以在另一个源文件/ 数据中分离对应的功能, 并将该文件编译为 NTDDI_ VISTA 。 然后, 只有当您不在 XP 上时, 才会调用 vita 特定功能 。

请注意, 如果您在应用程序中加入 SHGetKnownFolderPath 的直接呼叫, 它将不会在 Windows XP 上工作, 因为 XP 上不存在 API 。 因此您必须使用 MaxLibrary/ GetProcAddress 来调用 API 。

变动

#define NTDDI_VERSION NTDDI_WINXP

#define NTDDI_VERSION NTDDI_VISTA

在声明 ShlObj 页眉前

窗口 10 的罚款工作





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签