Some of you may already know that there's a new Ex version of IoSetCompletionRoutine that is meant to prevent non-PnP drivers from unloading prematurely. What you might not realize though is that this routine actually returns an NTSTATUS value, which means that you?re going to have to handle the possible error condition.
Another "gotcha" is that IoSetCompletionRoutineEx allocates memory to be used as a context block and this context is not freed until completion processing occurs for the stack location. Therefore, once your driver calls IoSetCompletionRoutineEx the IRP must be passed on to another driver. Otherwise, your completion routine never runs and your driver will leak the pool the I/O Manager allocated.