Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hello World driver won't compile correctly

I started out driver development, however I followed some tutorials I met online here and I am trying to compile my driver into a simple .sys file.

The code looks like this:

#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;
}

Rather than compile, I get this very funny error:

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

I am lost as I dont know where else to seek answers from. I have checked and checked all and I get this funny error which happens to work fine on other versions of Visual studio. If I remove the warnings, I don't see it to have a worry, it compiles fine and does not send any errors to my screen, why is this so?

I am using Visual studio 2019, what could I apparently be missing ??

PS

The warnings I get look like this

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  
like image 638
Isildor Avatar asked May 19 '19 08:05

Isildor


2 Answers

Looks like an issue with Visual Studio: https://developercommunity.visualstudio.com/content/problem/549389/intellisense-error-e1097-because-intellisense-does.html

Here is a copy from that link:

With Visual C++ 2017 version 15.8 (compiler version 19.15.26726.0) a new undocumented Compiler option /d1initall and a new attribute __declspec(no_init_all) got added to the Compiler. Intellisense (VS17 and 19) does not recognize this attribute and says its unknown.

The Problem is Intellisense not knowing about the existence of the no_init_all attribute.

This attribute is used in the official Windows SDK and WDK 10.0.18362.0 header files, that means Intellisense displays this error for all projects that include Windows Kits\10\Include\10.0.18362.0\um\winnt.h (Line 588 & 1093) or Windows Kits\10\Include\10.0.18362.0\km\ntddk.h (Line 7597).

You can also reproduce the Error by simply defining a struct with __declspec(no_init_all) Attribute,

__declspec(no_init_all) struct A {}; This Compiles fine without any warnings/errors but Intellisense says its wrong.


It has been fixed on 29th of April, 2019.

like image 91
Csaba Avatar answered Oct 17 '22 13:10

Csaba


A possible fix is to add this code to one of the main header files:

#if (_MSC_VER >= 1915)
#define no_init_all deprecated
#endif
like image 45
Pedro Ferreira Avatar answered Oct 17 '22 13:10

Pedro Ferreira