【问题标题】:Why can I not declare a variable whose structure has been defined?为什么我不能声明结构已定义的变量?
【发布时间】:2013-02-10 22:16:32
【问题描述】:

这个问题可能不像你最初想象的那么容易解决。

FILTER_MESSAGE_HEADER 是在头文件 fltUserStructures.h 中定义的结构,它是位于 SDK 包含路径的标准 Windows SDK 头文件,即

"C:\Program Files (x86)\Windows Kits\8.0\Include\shared\fltUserStructures.h"。

typedef struct _FILTER_MESSAGE_HEADER {

    //
    //  OUT
    //
    //  Total buffer length in bytes, including the FILTER_REPLY_HEADER, of
    //  the expected reply.  If no reply is expected, 0 is returned.
    //

    ULONG ReplyLength;

    //
    //  OUT
    //
    //  Unique Id for this message.  This will be set when the kernel message
    //  satifies this FilterGetMessage or FilterInstanceGetMessage request.
    //  If replying to this message, this is the MessageId that should be used.
    //

    ULONGLONG MessageId;

    //
    //  General filter-specific buffer data follows...
    //

} FILTER_MESSAGE_HEADER, *PFILTER_MESSAGE_HEADER;

但是,VC++ 2012 无法编译以下代码。

#include <fltUserStructures.h>

int main()
{
    //
    // error C2065: 'FILTER_MESSAGE_HEADER' : undeclared identifier
    //
    FILTER_MESSAGE_HEADER v; 
}

#define NTDDI_VERSION 0x06000000 // Vista or later
#include <FltUser.h>

int main()
{
    //
    // fltuserstructures.h(27): fatal error C1012:
    // unmatched parenthesis : missing ')'
    //
    FILTER_MESSAGE_HEADER v; 
}

虽然我尝试了很多方法,但编译器总是拒绝上面的代码。根本原因是什么?

【问题讨论】:

  • 对于我们这些没有安装 Windows SDK 的人来说,结构的定义是什么样的?
  • 尝试包含 FltUser.h
  • @André,包括 FltUser.h 会产生另一个错误:致命错误 C1012:不匹配的括号:缺少')'
  • 不知道为什么这被否决了...

标签: c windows compiler-errors macros c-preprocessor


【解决方案1】:

该结构(以及fltUserStructures.h 中的大部分内容是基于FLT_MGR_BASELINE 有条件地编译的,而FLT_MGR_BASELINE 又设置在fltUser.h 中:

#define FLT_MGR_BASELINE (((OSVER(NTDDI_VERSION) == NTDDI_WIN2K) && (SPVER(NTDDI_VERSION) >= SPVER(NTDDI_WIN2KSP4))) || \
                          ((OSVER(NTDDI_VERSION) == NTDDI_WINXP) && (SPVER(NTDDI_VERSION) >= SPVER(NTDDI_WINXPSP2))) || \
                          ((OSVER(NTDDI_VERSION) == NTDDI_WS03)  && (SPVER(NTDDI_VERSION) >= SPVER(NTDDI_WS03SP1))) ||  \
                          (NTDDI_VERSION >= NTDDI_VISTA))

所以,改为#include &lt;fltuser.h&gt;,并确保正确设置NTDDI_VERSION(例如使用WINVER):

#define WINVER 0x0600
#include <windows.h>
#include <fltUser.h>

int main()
{
    //
    // error C2065: 'FILTER_MESSAGE_HEADER' : undeclared identifier
    //
    FILTER_MESSAGE_HEADER v; 
}

【讨论】:

  • 此解决方案不起作用。 “致命错误 C1012:括号不匹配:缺少 ')'”
  • 修改后的版本还不行。 “sdkddkver.h(264): 致命错误 C1189: #error: NTDDI_VERSION 设置与 _WIN32_WINNT 设置冲突”
  • 我从您的帖子中复制了代码。即#define WINVER 0x0600 #include #include
  • 看起来您的项目已经在设置_WIN32_WINNT - 更改它以表明您需要 Vista API (0x0600)。有关可怕的细节,请参阅msdn.microsoft.com/en-us/library/windows/desktop/aa383745.aspx
  • 这次真的有效。根本原因正如您所指出的那样。
猜你喜欢
  • 2011-11-02
  • 2016-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多