Condividi tramite


Specificare una funzione di scarico

Un driver callout deve fornire una funzione di scaricamento. Il sistema operativo chiama questa funzione quando il driver del callout viene scaricato dal sistema. La funzione di scaricamento di un driver callout deve garantire che i callout del driver siano deregistrati dal motore di filtro prima che il driver callout venga scaricato dalla memoria di sistema. Un driver callout non può essere scaricato dal sistema se non fornisce una funzione di scaricamento.

Il modo in cui un driver callout specifica una funzione di scaricamento 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, specifica una funzione Unload nella funzione DriverEntry . Per esempio:

VOID
 Unload(
    IN PDRIVER_OBJECT DriverObject
    );

NTSTATUS
 DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{
  ...

  // Specify the callout driver's Unload function
 DriverObject->DriverUnload = Unload;

  ...
}

WDF-Based Driver di Richiamo

Se un driver callout è basato su WDF, specifica una funzione EvtDriverUnload nella funzione DriverEntry . Per esempio:

VOID
 Unload(
    IN WDFDRIVER Driver
    );

NTSTATUS
 DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{
  NTSTATUS status;
  WDF_DRIVER_CONFIG config;
  WDFDRIVER driver;

  ...

  // Initialize the driver config structure
  WDF_DRIVER_CONFIG_INIT(&config, NULL);

  // Indicate that this is a non-PNP driver
 config.DriverInitFlags = WdfDriverInitNonPnpDriver;

  // Specify the callout driver's Unload function
 config.EvtDriverUnload = Unload;

  // Create a WDFDRIVER object
 status =
 WdfDriverCreate(
 DriverObject,
 RegistryPath,
      NULL,
      &config,
      &driver
      );

  ...

 return status;
}

Per informazioni su come implementare la funzione di scaricamento di un driver callout, vedere Scaricamento di un driver callout.