c - Hello World 驱动程序无法正确编译

标签 c visual-studio driver visual-studio-2019

我开始进行驱动程序开发,但是我遵循了我在网上遇到的一些教程,并且我正在尝试将我的驱动程序编译成一个简单的 .sys 文件。

代码如下所示:

#include <ntddk.h>
#include <wdf.h>

#define UNREFERENCED_PARAMETER(P) (P)
VOID DriverUnload(PDRIVER_OBJECT driver)
{
    DbgPrint("first:HelloWorld End!");
}

NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pUnicodeString)
{
    DbgPrint("first:HelloWorld Begin!");
    pDriverObject->DriverUnload = DriverUnload;
    return STATUS_SUCCESS;
}

我没有编译,而是得到了这个非常有趣的错误:

Error   C2220   warning treated as error - no 'object' file generated   MyHelloWorldDriver  C:\Users\****\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c 7   

我迷路了,因为我不知道还能从哪里寻求答案。我已经检查并检查了所有内容,我得到了这个有趣的错误,它恰好在其他版本的 Visual Studio 上工作正常。如果我删除警告,我认为它不会担心,它编译正常并且不会向我的屏幕发送任何错误,为什么会这样?

我正在使用 Visual Studio 2019,我显然缺少什么??

附言

我收到的警告看起来像这样

Error (active)  E1097   unknown attribute "no_init_all" MyHelloWorldDriver  C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\km\ntddk.h  372 
Error (active)  E1097   unknown attribute "no_init_all" MyHelloWorldDriver  C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\km\ntddk.h  1093    
Warning MSB8038 Spectre mitigation is enabled but Spectre mitigated libraries are not found.  Verify that the Visual Studio Workload includes the Spectre mitigated libraries.  See https://aka.ms/Ofhn4c for more information. MyHelloWorldDriver  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets 422 
Error   C2220   warning treated as error - no 'object' file generated   MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  7   
Warning C4566   character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252)    MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  7   
Warning C4100   'driver': unreferenced formal parameter MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  5   
Warning C4566   character represented by universal-character-name '\uFF01' cannot be represented in the current code page (1252)    MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  12  
Warning C4100   'pUnicodeString': unreferenced formal parameter MyHelloWorldDriver  C:\Users\***\source\repos\MyHelloWorldDriver\MyHelloWorldDriver\main.c  10  

最佳答案

看起来像是 Visual Studio 的问题: https://developercommunity.visualstudio.com/content/problem/549389/intellisense-error-e1097-because-intellisense-does.html

这是该链接的副本:

对于 Visual C++ 2017 版本 15.8(编译器版本 19.15.26726.0),一个新的未记录的编译器选项/d1initall 和 新属性 __declspec(no_init_all) 被添加到编译器中。 Intellisense(VS17 和 19)无法识别此属性并说它未知。

问题是 Intellisense 不知道 no_init_all 属性的存在。

该属性在官方Windows SDK和WDK 10.0.18362.0头文件中使用, 这意味着 Intellisense 会为所有包含的项目显示此错误 Windows Kits\10\Include\10.0.18362.0\um\winnt.h(第 588 和 1093 行)或 Windows 套件\10\Include\10.0.18362.0\km\ntddk.h(第 7597 行)。

您还可以通过简单地定义一个具有 __declspec(no_init_all) 属性的结构来重现错误,

__declspec(no_init_all) 结构 A {}; 这编译正常,没有任何警告/错误,但 Intellisense 说它错了。


已于 2019 年 4 月 29 日修复。

关于c - Hello World 驱动程序无法正确编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56206053/

相关文章:

c++ - 让 Visual Studio 跳过?

c++ - 从派生类访问基类成员时强制使用范围解析运算符

java - DB2 JDBC SSL 连接

c - 网络编程中如何完成tcp拆解的完整4步

c - 使用线程计算文件中单词出现次数的程序中的段错误

java - 用 C 或 Java 编写的简单 FTP 程序

PHP 和 VB.net - 相同的数据库

windows - 如何区分Windows驱动程序和dll

java - 为什么之前运行的代码中会出现错误 "Uninitialized constant DriverManager"?

c - 如何为 C 函数创建闭包