Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest driver with visual studio wdk

I'm trying to create a simplest "hello world" driver in Visual Studio 2012 with WDK. The code of Device.c file is this:

#include <ntddk.h>

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

    return STATUS_SUCCESS;
}

When building there's an error:

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.

What causes these errors?

like image 844
Sergey Avatar asked Mar 19 '26 13:03

Sergey


2 Answers

More recommended way is using UNREFERENCED_PARAMETER() macro, so your function can be changed to:

NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
    UNREFERENCED_PARAMETER(DriverObject);
    UNREFERENCED_PARAMETER(RegistryPath);

    DbgPrint("Hello, World");

    return STATUS_SUCCESS;
}
like image 55
Rohan Avatar answered Mar 21 '26 03:03

Rohan


The WDK has "Treat warning as error" activated, and unused parameters trigger a warning.

So if you change your code to :

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

    return STATUS_SUCCESS;
}

it should compile.

like image 34
Christopher Avatar answered Mar 21 '26 01:03

Christopher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!