I'm trying to create a filter driver. I installed the Windows DDK and the new templates show up in Visual Studio Community 2022. But when I create an XPS print filter driver, it doesn't compile. Either I'm missing definitions or stuff is redefined. ChatGPT is no help and giving up isn't an option.
I created an empty kernel mode driver project. I added a DLLMain and a DriverEntry. I include the following
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
#include <ntddk.h>
#include "Logger.h"
Logger.h only has a bare class without even a defined constructor. If I remove Windows.h, I'm missing defines. ntddk.h is necessary for the driver project. with them both, other stuff is redefined. What is the proper includes?
I don't know if it's relevant, but here is my DriverEntry
#include "Framework.h"
#include "DriverBase.h"
NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
{
UNREFERENCED_PARAMETER(RegistryPath);
DbgPrint("Print Filter Driver: DriverEntry called\n");
// Register the driver's major function callbacks
DriverObject->MajorFunction[IRP_MJ_CREATE] = PrintFilterCreate;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = PrintFilterClose;
DriverObject->MajorFunction[IRP_MJ_CLEANUP] = CleanupDispatch;
DriverObject->MajorFunction[IRP_MJ_WRITE] = PrintFilterWrite;
DriverObject->DriverUnload = PrintFilterUnload;
return STATUS_SUCCESS;
}
NTSTATUS PrintFilterCreate(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
{
UNREFERENCED_PARAMETER(DeviceObject);
DbgPrint("Print Filter Driver: IRP_MJ_CREATE called\n");
// Perform any necessary processing for the IRP_MJ_CREATE operation
// Complete the IRP
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
NTSTATUS PrintFilterClose(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
{
UNREFERENCED_PARAMETER(DeviceObject);
DbgPrint("Print Filter Driver: IRP_MJ_CLOSE called\n");
// Perform any necessary processing for the IRP_MJ_CLOSE operation
// Complete the IRP
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
NTSTATUS CleanupDispatch(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
{
UNREFERENCED_PARAMETER(DeviceObject);
DbgPrint("Print Filter Driver: IRP_MJ_CLEANUP called\n");
// Perform any necessary cleanup operations
// Complete the IRP
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_SUCCESS;
}
NTSTATUS PrintFilterWrite(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
{
UNREFERENCED_PARAMETER(DeviceObject);
DbgPrint("Print Filter Driver: IRP_MJ_WRITE called\n");
NTSTATUS status = STATUS_SUCCESS;
PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
// Process the write operation
// Access the data buffer through Irp->AssociatedIrp.SystemBuffer
// and the length of the data through irpStack->Parameters.Write.Length
// Complete the IRP
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = irpStack->Parameters.Write.Length;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
VOID PrintFilterUnload(_In_ PDRIVER_OBJECT DriverObject)
{
DbgPrint("Print Filter Driver: Unload called\n");
DbgPrint("Print Filter Driver: Unload complete\n");
}