Hello World driver won't compile correctly
Asked Answered
A

3

5

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  
Ally answered 19/5, 2019 at 8:31 Comment(7)
what is the warning?Marlomarlon
@YoYoYonnY i have updated Question see warnings thereAlly
the character is different from !.Marlomarlon
The messages seem very clear. What's the problem with them exactly?Hassler
@YoYoYonnY changed that, still have the error , should i remove the warnings, it compiles without problemsAlly
@n.m. i gave you the log of what i have. If i remove the warnings it compiles 100% no errorsAlly
Have you tried to read the warning messages and analyze what they say? Share your analysis.Hassler
L
5

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.

Laicize answered 5/6, 2019 at 10:3 Comment(3)
Can you provide more information? What happens if the above link is no longer valid?Slattery
Hi, can you clarify what you mean by 'it has been fixed'? I've updated VS2017 to the latest as of today, and I'm still having this issue.Pennell
i am having this issue as well and I am up to date. is there a way around it?Edmonson
E
5

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
Enwreathe answered 24/6, 2020 at 9:47 Comment(0)
R
0

you can activate precompiled header in Tools/option/Text-Editor/C C++/Extension and set Disable Automatic Precompiled Header to false.

Regulation answered 7/2, 2020 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.