A.3.12 Unloading and Deregistering Drivers

When the NDIS interface library calls MacUnload, as Figure A.3.12 shows, the function frees allocated resources and decrements the reference count in the NIC driver block to zero. MacUnload then calls NdisDeregisterMac to remove the NIC driver from the NDIS interface library wrapper connection. MacUnload passes a network interface card handle to the NIC driver descriptor block and NdisDeregisterMac sets the driver state to closing to prevent the NIC driver from registering additional network interface cards.

If the NIC driver is the last driver being unloaded and the network is shutting down, MacUnload makes a final call to NdisTerminateWrapper to close the NDIS interface library wrapper. Ndis TerminateWrapper is also called if, during driver initialization, NdisInitializeWrapper is successful but NdisRegisterMac fails to register any network interface cards.

When transports wish to unload, they call NdisDeregisterProtocol to remove themselves from the wrapper connection. For each call, this function decrements the reference count included in the transport driver block. When the count reaches zero, the transport driver block is freed.

Figure A.3.12 Unloading and deregistering drivers and terminating wrapper