Unloading a Server with Outstanding Context Handles

Traditionally, unloading a DLL that services RPC calls using context handles, without first stopping the hosting process, has been problematic. This is because the run-down routine is no longer valid when the DLL is being unloaded. When a client with a previously open context handle fails, and the RPC run time tries to close the context handle, its attempt to call the run-down routine access violates, and the server crashes.

Beginning with Windows XP, a new API called RpcServerUnregisterIfEx has been added. RpcServerUnregisterIfEx closes context handles opened by the interface being unregistered; the RpcServerUnregisterIf function does not. Using RpcServerUnregisterIfEx is not necessary when the entire process shuts down, but it is necessary if one or more DLLs hosting the run-down routines is unloaded while outstanding context handles exist.