Inizializzazione di strutture di dati NMR

Prima che un'applicazione Winsock Kernel (WSK) possa registrarsi con il registrar del modulo di rete (NMR), l'applicazione deve prima inizializzare le strutture seguenti.

Tutte queste strutture di dati devono rimanere valide e residenti in memoria, purché l'applicazione WSK sia registrata con nmr.

Nell'esempio di codice seguente viene illustrato come un'applicazione WSK può inizializzare tutte le strutture di dati elencate in precedenza.

// Include the WSK header file
#include "wsk.h"

// Structure for the WSK application's network module identification
const NPI_MODULEID ModuleId =
{
  sizeof(NPI_MODULEID),
  MIT_GUID,
  { ... }  // A GUID that uniquely identifies the WSK application
};

// Prototypes for the WSK application's NMR API callback functions
NTSTATUS
  ClientAttachProvider(
    IN HANDLE NmrBindingHandle,
    IN PVOID ClientContext,
    IN PNPI_REGISTRATION_INSTANCE ProviderRegistrationInstance
    );

NTSTATUS
  ClientDetachProvider(
    IN PVOID ClientBindingContext
    );

VOID
  ClientCleanupBindingContext(
    IN PVOID ClientBindingContext
    );

// Structure for the WSK application's characteristics
const NPI_CLIENT_CHARACTERISTICS Characteristics =
{
  0,
  sizeof(NPI_CLIENT_CHARACTERISTICS),
  ClientAttachProvider,
  ClientDetachProvider,
  ClientCleanupBindingContext,
  {
    0,
    sizeof(NPI_REGISTRATION_INSTANCE),
    &NPI_WSK_INTERFACE_ID,
    &ModuleId,
    0,
    NULL
  }
};

Un'applicazione WSK chiama la funzione NmrRegisterClient per registrare l'applicazione con NMR.

Per esempio:

// Variable to contain the handle for the registration with the NMR
HANDLE RegistrationHandle;

// DriverEntry function
NTSTATUS
  DriverEntry(
    PDRIVER_OBJECT DriverObject,
    PUNICODE_STRING RegistryPath
    )
{
  NTSTATUS Status;

  .
  .
  .

  // Register the WSK application with the NMR
  Status = NmrRegisterClient(
    &Characteristics,
    NULL,
    &RegistrationHandle
    );

  if(!NT_SUCCESS(Status)) {
      .
      .
      .
      return Status;
  }

  .
  .
  .
}

Un'applicazione WSK non è necessaria per chiamare NmrRegisterClient dall'interno della funzione DriverEntry . Ad esempio, se un'applicazione WSK è un sottocomponente di un driver complesso, la registrazione dell'applicazione può verificarsi solo quando viene attivato il sottocomponente dell'applicazione WSK.