Skip to content

Instantly share code, notes, and snippets.

@RChehowski
Created October 24, 2018 07:27
Show Gist options
  • Save RChehowski/6e4fcd2a2fc0c61e1ef19697f519a8ae to your computer and use it in GitHub Desktop.
Save RChehowski/6e4fcd2a2fc0c61e1ef19697f519a8ae to your computer and use it in GitHub Desktop.
int utf8_to_wide_char(const char* UTF8_string, wchar_t** OUT_wide_chars, size_t* OUT_size)
{
if (!UTF8_string)
return 1;
const size_t length = (size_t)MultiByteToWideChar(CP_UTF8, 0, UTF8_string, -1, NULL, 0);
wchar_t* wide_characters = (wchar_t*)malloc(length * sizeof(wchar_t));
if (!wide_characters)
{
return 1;
}
if (length > 0)
{
MultiByteToWideChar(CP_UTF8, 0, UTF8_string, -1, wide_characters, length);
}
if (OUT_wide_chars)
*OUT_wide_chars = wide_characters;
if (OUT_size)
*OUT_size = length;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment