Unify the try/finally blocks around win32 calls