为什么我不能声明一个已经定义了结构的变量?

时间:2013-02-10 22:16:32

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

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

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

  

“C:\ Program Files(x86)\ Windows   试剂盒\ 8.0 \包括\共享\ 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; 
}

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

1 个答案:

答案 0 :(得分:2)

该结构(以及fltUserStructures.h中的大部分内容是根据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 <fltuser.h>

所以,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; } ):

{{1}}