【问题标题】:Simplest driver with visual studio wdk最简单的带有visual studio wdk的驱动程序
【发布时间】:2012-10-19 15:29:25
【问题描述】:

我正在尝试使用 WDK 在 Visual Studio 2012 中创建一个最简单的“hello world”驱动程序。 Device.c文件的代码是这样的:

#include <ntddk.h>

NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
    DbgPrint("Hello, World");

    return STATUS_SUCCESS;
}

构建时出现错误:

1>Driver.c(3): error C2220: warning treated as error - no 'object' file generated
1>Driver.c(3): warning C4100: 'RegistryPath' : unreferenced formal parameter
1>Driver.c(3): warning C4100: 'DriverObject' : unreferenced formal parameter
2>------ Build started: Project: KMDFSmall Package, Configuration: Win7 Debug x64 ------
2>C:\Program Files (x86)\Windows Kits\8.0\build\WindowsDriver8.0.common.targets(1347,5): error MSB3030: Could not copy the file "Path\To\Projects\SimpleDriver\x64\Win7Debug\KMDFSmall.sys" because it was not found.

导致这些错误的原因是什么?

【问题讨论】:

    标签: visual-studio-2012 driver wdk


    【解决方案1】:

    更推荐的方式是使用UNREFERENCED_PARAMETER()宏,所以你的函数可以改为:

    NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
    {
        UNREFERENCED_PARAMETER(DriverObject);
        UNREFERENCED_PARAMETER(RegistryPath);
    
        DbgPrint("Hello, World");
    
        return STATUS_SUCCESS;
    }
    

    【讨论】:

      【解决方案2】:

      WDK 已激活“将警告视为错误”,未使用的参数会触发警告。

      因此,如果您将代码更改为:

      NTSTATUS DriverEntry(PDRIVER_OBJECT /*DriverObject*/, PUNICODE_STRING /*RegistryPath*/)
      {
          DbgPrint("Hello, World");
      
          return STATUS_SUCCESS;
      }
      

      它应该编译。

      【讨论】:

      • 你是对的,我只是将Treat warning as error设置为NO就可以了
      【解决方案3】:

      更短的方法是使用 IN:

      #include <ntddk.h>
      
      NTSTATUS DriverEntry(IN PDRIVER_OBJECT theDriverObject, IN PUNICODE_STRING theRegistryPath) {
          DbgPrint("Hello World!\n");
          return STATUS_SUCCESS;
      }
      

      来源:颠覆 Windows 内核:Greg Hoglund 和 James Butler 的 Rootkits

      【讨论】:

        猜你喜欢
        • 2018-04-17
        • 2013-07-08
        • 2021-11-26
        • 1970-01-01
        • 2012-06-27
        • 1970-01-01
        • 2021-08-06
        • 1970-01-01
        • 2017-10-29
        相关资源
        最近更新 更多