The WS2_32.DLL(and layered protocols) will call WSPCleanup once for each invocation of WSPStartup. On each invocation, WSPCleanup should decrement a per-process reference counter, and when the counter reaches zero the service provider must prepare itself to be unloaded from memory. The first order of business is to finish transmitting any unsent data on sockets that are configured for a graceful close. Thereafter, any and all resources held by the provider are to be freed. The service provider must be left in a state where it can be immediately re-initialized by a call to WSPStartup.