C语言 无法在不修改 Windows 标头的情况下使用 VC2015 构建 WDK 10 示例



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

  • 包含目录

    C:\WinSDK10\包含\10.0.10586.0\shared;
    C:\WinSDK10\包含\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: DriverEntryn"));
    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: KmdfHelloWorldEvtDeviceAddn"));
    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:WinSDK10Include10.0.10586.0kmwdm.h   31789   
Error   C2146   syntax error: missing ')' before identifier 'InformationClass'  Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31789   
Error   C2061   syntax error: identifier 'InformationClass' Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31789   
Error   C2061   syntax error: identifier 'InformationClass' Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31789   
Error   C2059   syntax error: ';'   Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31789   
Error   C2059   syntax error: ';'   Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31789   
Error   C2059   syntax error: ','   Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31789   
Error   C2059   syntax error: ','   Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31789   
Error   C2059   syntax error: ')'   Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31792   
Error   C2059   syntax error: ')'   Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31792   
Error   C2081   'EVENT_INFO_CLASS': name in formal parameter list illegal   Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31789   
Error   C2081   'EVENT_INFO_CLASS': name in formal parameter list illegal   Test1   C:WinSDK10Include10.0.10586.0kmwdm.h   31789   

黑客:如果我编辑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 驱动程序示例链接时做错了什么,但我无法弄清楚是什么。

谢谢你的时间,

克里斯

下一版本的 WDK (10.0.14393) 遇到类似问题。看起来在这两种情况下,问题都是不同版本的 Win SDK 和 WDK。通过安装相应版本的 Win SDK 来解决。本答案中有更多详细信息。

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

如错误消息中所建议的,在文件C:WinSDK10Include10.0.10586.0kmwdm.h中查找有关 InformationClass 之前未定义的内容的线索。 然后包括提供定义的头文件。

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

此链接包含有关驱动程序注释(Microsoft源代码注释语言 (SAL))的信息。

该错误指示找不到EVENT_INFO_CLASS的定义(在 evntprov.h 中定义)。另一个有趣的事情是,您正在为方法 EtwSetInformation 的行号 31789 获取此内容。此方法只需为 (NTDDI_VERSION>= NTDDI_THRESHOLD) 导入,并且你的目标是 Win8.1。这里有些不对劲。请共享诊断 msbuild 日志。分析会有所帮助。

相关内容

最新更新