use SafeHandle to manage user32 lifecycle (fixes #1593)

See #1593 for description.