Improved error handling

Signed-off-by: Sven Strickroth <email@cs-ware.de>
Deduplicate FormatMessage UTF-16 to UTF-8 conversion code

Signed-off-by: Sven Strickroth <email@cs-ware.de>