diff --git a/src/win32_init.c b/src/win32_init.c index b23e7d57..8f6015bd 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -131,6 +131,60 @@ static void freeLibraries(void) } +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Returns a wide string version of the specified UTF-8 string +//======================================================================== + +WCHAR* _glfwCreateWideStringFromUTF8(const char* source) +{ + WCHAR* target; + int length; + + length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0); + if (!length) + return NULL; + + target = (WCHAR*) _glfwMalloc(sizeof(WCHAR) * (length + 1)); + + if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1)) + { + _glfwFree(target); + return NULL; + } + + return target; +} + + +//======================================================================== +// Returns a UTF-8 string version of the specified wide string +//======================================================================== + +char* _glfwCreateUTF8FromWideString(const WCHAR* source) +{ + char* target; + int length; + + length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL); + if (!length) + return NULL; + + target = (char*) _glfwMalloc(length + 1); + + if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length + 1, NULL, NULL)) + { + _glfwFree(target); + return NULL; + } + + return target; +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/win32_platform.h b/src/win32_platform.h index 0d63e09c..0e9a4e1f 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -325,6 +325,10 @@ typedef struct _GLFWlibraryWin32 // Prototypes for platform specific internal functions //======================================================================== +// Wide strings +WCHAR* _glfwCreateWideStringFromUTF8(const char* source); +char* _glfwCreateUTF8FromWideString(const WCHAR* source); + // Time void _glfwInitTimer(void); diff --git a/src/win32_window.c b/src/win32_window.c index 6ebe07b4..bf66fee4 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -34,31 +34,6 @@ #include -//======================================================================== -// Convert the specified UTF-8 string to a wide string -//======================================================================== - -static WCHAR* createWideStringFromUTF8(const char* source) -{ - WCHAR* target; - int length; - - length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0); - if (!length) - return NULL; - - target = (WCHAR*) _glfwMalloc(sizeof(WCHAR) * (length + 1)); - - if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1)) - { - _glfwFree(target); - return NULL; - } - - return target; -} - - //======================================================================== // Convert BPP to RGB bits based on "best guess" //======================================================================== @@ -1357,7 +1332,7 @@ static int createWindow(_GLFWwindow* window, else SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0); - wideTitle = createWideStringFromUTF8(wndconfig->title); + wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title); if (!wideTitle) { _glfwSetError(GLFW_PLATFORM_ERROR, @@ -1604,7 +1579,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) { - WCHAR* wideTitle = createWideStringFromUTF8(title); + WCHAR* wideTitle = _glfwCreateWideStringFromUTF8(title); if (!wideTitle) { _glfwSetError(GLFW_PLATFORM_ERROR,