Initializing NMR Data Structures
Before a Winsock Kernel (WSK) application can register with the Network Module Registrar (NMR), the application must first initialize the following structures.
NPI_REGISTRATION_INSTANCE contained within the NPI_CLIENT_CHARACTERISTICS structure
All of these data structures must remain valid and resident in memory as long as the WSK application is registered with the NMR.
The following code example shows how a WSK application can initialize all of the data structures listed previously.
// 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
}
};
A WSK application calls the NmrRegisterClient function to register the application with the NMR.
For example:
// 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;
}
.
.
.
}
A WSK application is not required to call NmrRegisterClient from within its DriverEntry function. For example, if a WSK application is a subcomponent of a complex driver, the registration of the application might occur only when the WSK application subcomponent is activated.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for