Make the different helper functions all return actual error codes. Avoid code duplication between ANSI and Unicode variant of those functions.