mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-27 02:46:08 +08:00
windows: Manage WideCharToMultiByte vs Windows XP.
Reference Issue #8666.
This commit is contained in:
@@ -376,6 +376,16 @@ SDL_AudioFormat SDL_WaveFormatExToSDLFormat(WAVEFORMATEX *waveformat)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int WIN_WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar)
|
||||||
|
{
|
||||||
|
if (WIN_IsWindowsXP()) {
|
||||||
|
dwFlags &= ~WC_ERR_INVALID_CHARS; // not supported before Vista. Without this flag, it will just replace bogus chars with U+FFFD. You're on your own, WinXP.
|
||||||
|
}
|
||||||
|
return WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpDefaultChar, lpUsedDefaultChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Win32-specific SDL_RunApp(), which does most of the SDL_main work,
|
/* Win32-specific SDL_RunApp(), which does most of the SDL_main work,
|
||||||
based on SDL_windows_main.c, placed in the public domain by Sam Lantinga 4/13/98 */
|
based on SDL_windows_main.c, placed in the public domain by Sam Lantinga 4/13/98 */
|
||||||
#ifdef SDL_PLATFORM_WIN32
|
#ifdef SDL_PLATFORM_WIN32
|
||||||
|
|||||||
@@ -173,6 +173,9 @@ extern BOOL WIN_IsRectEmpty(const RECT *rect);
|
|||||||
|
|
||||||
extern SDL_AudioFormat SDL_WaveFormatExToSDLFormat(WAVEFORMATEX *waveformat);
|
extern SDL_AudioFormat SDL_WaveFormatExToSDLFormat(WAVEFORMATEX *waveformat);
|
||||||
|
|
||||||
|
/* WideCharToMultiByte, but with some WinXP manangement. */
|
||||||
|
extern int WIN_WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar);
|
||||||
|
|
||||||
/* Ends C function definitions when using C++ */
|
/* Ends C function definitions when using C++ */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -795,13 +795,21 @@ end:
|
|||||||
static char *hid_internal_UTF16toUTF8(const wchar_t *src)
|
static char *hid_internal_UTF16toUTF8(const wchar_t *src)
|
||||||
{
|
{
|
||||||
char *dst = NULL;
|
char *dst = NULL;
|
||||||
|
#ifdef HIDAPI_USING_SDL_RUNTIME
|
||||||
|
int len = WIN_WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, src, -1, NULL, 0, NULL, NULL);
|
||||||
|
#else
|
||||||
int len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, src, -1, NULL, 0, NULL, NULL);
|
int len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, src, -1, NULL, 0, NULL, NULL);
|
||||||
|
#endif
|
||||||
if (len) {
|
if (len) {
|
||||||
dst = (char*)calloc(len, sizeof(char));
|
dst = (char*)calloc(len, sizeof(char));
|
||||||
if (dst == NULL) {
|
if (dst == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
#ifdef HIDAPI_USING_SDL_RUNTIME
|
||||||
|
WIN_WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, src, -1, dst, len, NULL, NULL);
|
||||||
|
#else
|
||||||
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, src, -1, dst, len, NULL, NULL);
|
WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, src, -1, dst, len, NULL, NULL);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
|
|||||||
@@ -973,7 +973,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|||||||
};
|
};
|
||||||
|
|
||||||
char utf8[5];
|
char utf8[5];
|
||||||
int result = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16, -1, utf8, sizeof(utf8), NULL, NULL);
|
int result = WIN_WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16, -1, utf8, sizeof(utf8), NULL, NULL);
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
SDL_SendKeyboardText(utf8);
|
SDL_SendKeyboardText(utf8);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ void WINRT_ProcessCharacterReceivedEvent(SDL_Window *window, Windows::UI::Core::
|
|||||||
};
|
};
|
||||||
|
|
||||||
char utf8[5];
|
char utf8[5];
|
||||||
|
// doesn't need to be WIN_WideCharToMultiByte, since we don't care about WinXP support in WinRT.
|
||||||
int result = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16, -1, utf8, sizeof(utf8), NULL, NULL);
|
int result = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, utf16, -1, utf8, sizeof(utf8), NULL, NULL);
|
||||||
if (result > 0) {
|
if (result > 0) {
|
||||||
SDL_SendKeyboardText(utf8);
|
SDL_SendKeyboardText(utf8);
|
||||||
|
|||||||
Reference in New Issue
Block a user