Creazione di un oggetto dispositivo (Piattaforma di filtro di Windows)

Un driver di callout deve creare un oggetto dispositivo prima di poter registrare i suoi callout con il motore di filtro. Il modo in cui un driver callout crea un oggetto dispositivo dipende dal fatto che il driver del callout sia basato sul modello di driver Windows (WDM) o su Windows Driver Framework (WDF).

Richiamo driver WDM-Based

Se un driver callout è basato su WDM, esso crea un oggetto dispositivo, chiamando la funzione IoCreateDevice. Per esempio:

PDEVICE_OBJECT deviceObject;

NTSTATUS
 DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{
  NTSTATUS status;

  ...

  // Create a device object
 status =
 IoCreateDevice(
 DriverObject,
      0,
      NULL,
      FILE_DEVICE_UNKNOWN,
      FILE_DEVICE_SECURE_OPEN,
      FALSE,
      &deviceObject
      );

  ...

 return status;
}

WDF-Based Driver di Richiamo

Se un driver di callout è basato su WDF, crea un oggetto dispositivo framework chiamando la funzione WdfDeviceCreate. Per registrare i callout con il motore di filtro, un driver callout basato su WDF deve ottenere un riferimento all'oggetto dispositivo WDM associato a l'oggetto dispositivo framework. Un driver di callout basato su WDF ottiene un puntatore a questo oggetto dispositivo WDM invocando la funzione WdfDeviceWdmGetDeviceObject. Per esempio:

WDFDEVICE wdfDevice;

NTSTATUS
 DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{
  WDFDRIVER driver;
  PWDFDEVICE_INIT deviceInit;
  PDEVICE_OBJECT deviceObject;
  NTSTATUS status;

  ...

  // Allocate a device initialization structure
 deviceInit =
 WdfControlDeviceInitAllocate(
    driver;
    &SDDL_DEVOBJ_KERNEL_ONLY
    );

  // Set the device characteristics
 WdfDeviceInitSetCharacteristics(
    deviceInit,
    FILE_DEVICE_SECURE_OPEN,
    FALSE
    );

  // Create a framework device object
 status =
 WdfDeviceCreate(
    &deviceInit,
    WDF_NO_OBJECT_ATTRIBUTES,
    &wdfDevice
    );

  // Check status
 if (status == STATUS_SUCCESS) {

    // Initialization of the framework device object is complete
    WdfControlFinishInitializing(
      wdfDevice
    );

    // Get the associated WDM device object
    deviceObject = WdfDeviceWdmGetDeviceObject(wdfDevice);
  }

  ...

 return status;
}