【问题标题】:Unable to build WDK 10 samples with VC2015 without modifying Windows headers无法在不修改 Windows 标头的情况下使用 VC2015 构建 WDK 10 示例
【发布时间】:2016-02-24 13:26:11
【问题描述】:

我正在运行全新安装的 Windows。除了 VC 和 SDK 没有安装其他程序

  • 包括目录

    C:\WinSDK10\Include\10.0.10586.0\shared;
    C:\WinSDK10\Include\10.0.10586.0\km;
    C:\WinSDK10\Include\10.0.10586.0\km\crt;
    C:\WinSDK10\Include\wdf\kmdf\1.11

  • 目标操作系统版本

    Windows 8.1

  • 目标平台

    桌面

  • 运行 Wpp 跟踪

    否

  • 启用最小重建

    否


来源:
#include <ntddk.h>
#include <wdf.h>
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;

NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT  DriverObject, _In_ PUNICODE_STRING RegistryPath)
{
    NTSTATUS status;
    WDF_DRIVER_CONFIG config;

    KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n"));
    WDF_DRIVER_CONFIG_INIT(&config, KmdfHelloWorldEvtDeviceAdd);
    status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);
    return status;
}

NTSTATUS KmdfHelloWorldEvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit)
{
    NTSTATUS status;
    WDFDEVICE hDevice;
    UNREFERENCED_PARAMETER(Driver);

    KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n"));
    status = WdfDeviceCreate(&DeviceInit, WDF_NO_OBJECT_ATTRIBUTES, &hDevice);
    return status;
}

Severity    Code    Description Project File    Line    Suppression State
Error   C2146   syntax error: missing ')' before identifier 'InformationClass'  Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   
Error   C2146   syntax error: missing ')' before identifier 'InformationClass'  Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   
Error   C2061   syntax error: identifier 'InformationClass' Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   
Error   C2061   syntax error: identifier 'InformationClass' Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   
Error   C2059   syntax error: ';'   Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   
Error   C2059   syntax error: ';'   Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   
Error   C2059   syntax error: ','   Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   
Error   C2059   syntax error: ','   Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   
Error   C2059   syntax error: ')'   Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31792   
Error   C2059   syntax error: ')'   Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31792   
Error   C2081   'EVENT_INFO_CLASS': name in formal parameter list illegal   Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   
Error   C2081   'EVENT_INFO_CLASS': name in formal parameter list illegal   Test1   C:\WinSDK10\Include\10.0.10586.0\km\wdm.h   31789   

Hack:如果我编辑 wdm.h 并删除 #define _ETW_KM_,驱动程序构建成功

wdm.h

#ifndef _ETW_KM_
#define _ETW_KM_
#endif

#include <evntprov.h>


//
// Optional callback function that users provide.
//

typedef
_IRQL_requires_max_(PASSIVE_LEVEL)
_IRQL_requires_same_
VOID
NTAPI 
ETWENABLECALLBACK (
    _In_ LPCGUID SourceId,
    _In_ ULONG ControlCode,
    _In_ UCHAR Level,
    _In_ ULONGLONG MatchAnyKeyword,
    _In_ ULONGLONG MatchAllKeyword,
    _In_opt_ PEVENT_FILTER_DESCRIPTOR FilterData,
    _Inout_opt_ PVOID CallbackContext
    );

typedef ETWENABLECALLBACK *PETWENABLECALLBACK;

抱歉这篇文章太长了!!
我很确定我在关注此 MSDN Driver Example Link 时做错了什么,但我不知道是什么。

感谢您的宝贵时间,

克里斯

【问题讨论】:

  • 驱动注解在 Driverspecs.h 中定义。 (对于诸如 _IRQL_requires_same_ 之类的东西)。你有这个 .h 文件包含在任何地方吗?
  • @ryyker 我没有直接包含driverspecs.h,但我已经包含了它所在的目录;即10.0.10586.0\shared。直接包含在&lt;ntddk.h&gt;上面,没有效果。
  • syntax error: missing ) 在未定义宏时很常见。您必须确保定义了所有标识符。一旦完成,其余的错误消息也可能会得到解决。
  • @ryyker 删除 _ETW_KM_ 可解决 所有 错误,因为否则无法达到 evntprov.h 中的 EVENT_INFO_CLASS。但这是一个 hack,出了点问题。
  • 我按照 MSDN 指南逐字进行了干净的 Windows 安装,可能是 WDK 中的错误?

标签: c visual-studio-2015 driver wdk windows-kernel


【解决方案1】:

在下一个版本的 WDK (10.0.14393) 中遇到了类似的问题。 看起来在这两种情况下,问题都是 Win SDK 和 WDK 的不同版本。 通过安装对应版本的Win SDK解决。 更多详情请查看this answer。

【讨论】:

  • WSDK 和 WDK 的版本并不总是匹配。
【解决方案2】:

看起来像一个未定义的标识符或宏...
您的第一条错误消息 (syntax error: missing ')' before identifier) 可能是理解问题的最佳关键。 其余的可能是该结果的结果,这可能是抱怨_IRQL_requires_same_(或其他标识符之一)未定义。

按照错误消息中的建议,查看文件C:\WinSDK10\Include\10.0.10586.0\km\wdm.h 以了解InformationClass 之前未定义的内容。然后包含提供定义的头文件。

(目前,您的帖子中没有任何信息将错误消息中列出的行号 31789 与源代码中的确切对应行联系起来。)

此链接包含有关 driver annotations(Microsoft 源代码注释语言 (SAL))的信息。

【讨论】:

  • 您的链接已损坏删除).
  • @I. - 是的,对不起。固定。
【解决方案3】:

错误表明未找到 EVENT_INFO_CLASS(在 evntprov.h 中定义)的定义。另一件有趣的事情是,您在方法 EtwSetInformation 的第 31789 行得到了这个。只需为 (NTDDI_VERSION >= NTDDI_THRESHOLD) 导入此方法,并且您的目标是 Win8.1。这里不对劲。请分享诊断 msbuild 日志。分析一下会很有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    相关资源
    最近更新 更多