BSOD on starting service Helloworld

Hey All,
I’m beginner. I wrote a simple “Helloworld” program in Visual Studio 2019 and builded it . I installed driver with Helloworld.sys by OSRLOADER. But when i start service, BSoD occurs.

Here is my code:
#include <ntddk.h>
#include <wdf.h>

DRIVER_INITIALIZE DriverEntry;

NTSTATUS DriverEntry(
In PDRIVER_OBJECT DriverObject,
In PUNICODE_STRING RegistryPath
)
{
// NTSTATUS variable to record success or failure
NTSTATUS status = STATUS_SUCCESS;

// Allocate the driver configuration object
WDF_DRIVER_CONFIG config;

// Print "Hello World" for DriverEntry
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n"));

// Finally, create the driver object
status = WdfDriverCreate(DriverObject,
	RegistryPath,
	WDF_NO_OBJECT_ATTRIBUTES,
	&config,
	WDF_NO_HANDLE
);
return status;

}

Someone please help me :frowning:
Thanks,
Khanh

You need to initialize the WDF_DRIVER_CONFIG using WDF_DRIVER_CONFIG_INIT.

Peter

I tried but still have this error.

#include <ntddk.h>
#include <wdf.h>
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;

NTSTATUS
DriverEntry(
In PDRIVER_OBJECT DriverObject,
In PUNICODE_STRING RegistryPath
)
{
// NTSTATUS variable to record success or failure
NTSTATUS status = STATUS_SUCCESS;

// Allocate the driver configuration object
WDF_DRIVER_CONFIG config;

// Print "Hello World" for DriverEntry
KdPrintEx(( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n" ));

// Initialize the driver configuration object to register the
// entry point for the EvtDeviceAdd callback, KmdfHelloWorldEvtDeviceAdd
WDF_DRIVER_CONFIG_INIT(&config, 
                       KmdfHelloWorldEvtDeviceAdd
                       );

// Finally, create the driver object
status = WdfDriverCreate(DriverObject, 
                         RegistryPath, 
                         WDF_NO_OBJECT_ATTRIBUTES, 
                         &config, 
                         WDF_NO_HANDLE
                         );
return status;

}

NTSTATUS
KmdfHelloWorldEvtDeviceAdd(
In WDFDRIVER Driver,
Inout PWDFDEVICE_INIT DeviceInit
)
{
// We’re not using the driver object,
// so we need to mark it as unreferenced
UNREFERENCED_PARAMETER(Driver);

NTSTATUS status;

// Allocate the device object
WDFDEVICE hDevice;    

// Print "Hello World"
KdPrintEx(( DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n" ));

// Create the device object
status = WdfDeviceCreate(&DeviceInit, 
                         WDF_NO_OBJECT_ATTRIBUTES,
                         &hDevice
                         );
return status;

}

What does the crash dump say? Post the output of !analyze -v… look at the log with !wdfkd.wdflogdump.

Posting one message at a time in this forum is, by the way, a terrible way to learn how to write a driver. Read a book. Red the WDK docs. Take a class. But just throwing some code together and asking people online “why does this crash?” I suspect won’t be too effective in helping you learn what you’re doing.

Peter

Thank you very much for your advice.
Khanh

You seem not to initialize the DeviceInit structure In your EtvAddDevice. This should be done similarly to the config one in your DriverEntry.

Also, you may run into BSOD (0x7f) if you compile the driver for Windows 8 and later versions and attempt to load it on Windows 7 (and possibly older). To solve this issue (if this is an issue for you), you should compile your driver for Windows 7.

Martin, your first sentence is wrong. The WDFDEVICE_INIT is opaque; it is initialized by the framework, is handed to the EvtDeviceAdd callback and gets passed to WdfDeviceCreate as is. You don’t re-initialize it.

Martin, your first sentence is wrong. The WDFDEVICE_INIT is opaque; it is initialized by the framework, is handed to the EvtDeviceAdd callback and gets passed to WdfDeviceCreate as is. You don’t re-initialize it.

I do apologise for the mistake. I somewhat missed that the WDFDEVICE_INIT was passed via parameters, so I expected it needs to be initialized.