Here it is
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath)
{
PDEVICE_OBJECT DeviceObject;
UNICODE_STRING DriverName;
NTSTATUS Status;
int i;
RtlInitUnicodeString(&DriverName, L"\Device\DummyTest");
Status = IoCreateDevice(pDriverObject,
0,
&DriverName,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN,
FALSE, &DeviceObject);
if (Status == STATUS_SUCCESS)
DbgPrint(“Device created.\r\n”);
else
DbgPrint(“Problem with device creation.\r\n”);
DeviceObject->Flags &= (~DO_DEVICE_INITIALIZING);
for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
pDriverObject->MajorFunction[i] = Unsupported;
pDriverObject->MajorFunction[IRP_MJ_CREATE] = Create;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] = Close;
pDriverObject->MajorFunction[IRP_MJ_CLEANUP] = Cleanup;
pDriverObject->DriverUnload = DrvUnload;
return STATUS_SUCCESS;
}
VOID DrvUnload(PDRIVER_OBJECT DriverObject)
{
PDEVICE_OBJECT DeviceObject;
PDEVICE_OBJECT NextDevice;
DbgPrint(“Unload\r\n”);
DeviceObject = DriverObject->DeviceObject;
while (DeviceObject != NULL)
{
NextDevice = DeviceObject->NextDevice;
IoDeleteDevice(DeviceObject);
DeviceObject = NextDevice;
}
}
I link with
link /subsystem:native /driver:wdm /entry:DriverEntry entry.obj functions.obj ntoskrnl.lib /libpath:%winddk%\lib\crt\amd64 /libpath:%winddk%\lib\win7\amd64
compilation architecture AMD64
But wait you said it only works with non-PnP drivers. Which I thought WDM = PnP.
So what do I do? Do I need to learn to write *.inf files? To be able to unload?
How does the Device Manager actually do it?