WIN32: Make OSystem_Win32 UNICODE compatible
This commit is contained in:
parent
fbf16c5a58
commit
ee5162078e
3 changed files with 111 additions and 42 deletions
|
@ -53,10 +53,16 @@ BOOL VerifyVersionInfoFunc(LPOSVERSIONINFOEXA lpVersionInformation, DWORD dwType
|
|||
return verifyVersionInfo(lpVersionInformation, dwTypeMask, dwlConditionMask);
|
||||
}
|
||||
|
||||
HRESULT SHGetFolderPathFunc(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath) {
|
||||
typedef HRESULT (WINAPI *SHGetFolderPathFunc)(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPSTR pszPath);
|
||||
HRESULT SHGetFolderPathFunc(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath) {
|
||||
typedef HRESULT (WINAPI *SHGetFolderPathFunc)(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath);
|
||||
|
||||
SHGetFolderPathFunc pSHGetFolderPath = (SHGetFolderPathFunc)(void *)GetProcAddress(GetModuleHandle(TEXT("shell32.dll")), "SHGetFolderPathA");
|
||||
SHGetFolderPathFunc pSHGetFolderPath = (SHGetFolderPathFunc)(void *)GetProcAddress(GetModuleHandle(TEXT("shell32.dll")),
|
||||
#ifndef UNICODE
|
||||
"SHGetFolderPathA"
|
||||
#else
|
||||
"SHGetFolderPathW"
|
||||
#endif
|
||||
);
|
||||
if (pSHGetFolderPath)
|
||||
return pSHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath);
|
||||
|
||||
|
@ -80,7 +86,12 @@ bool confirmWindowsVersion(int majorVersion, int minorVersion) {
|
|||
return VerifyVersionInfoFunc(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, conditionMask);
|
||||
}
|
||||
|
||||
wchar_t *ansiToUnicode(const char *s, uint codePage) {
|
||||
wchar_t *ansiToUnicode(const char *s) {
|
||||
#ifndef UNICODE
|
||||
uint codePage = CP_ACP;
|
||||
#else
|
||||
uint codePage = CP_UTF8;
|
||||
#endif
|
||||
DWORD size = MultiByteToWideChar(codePage, 0, s, -1, NULL, 0);
|
||||
|
||||
if (size > 0) {
|
||||
|
@ -92,7 +103,12 @@ wchar_t *ansiToUnicode(const char *s, uint codePage) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char *unicodeToAnsi(const wchar_t *s, uint codePage) {
|
||||
char *unicodeToAnsi(const wchar_t *s) {
|
||||
#ifndef UNICODE
|
||||
uint codePage = CP_ACP;
|
||||
#else
|
||||
uint codePage = CP_UTF8;
|
||||
#endif
|
||||
DWORD size = WideCharToMultiByte(codePage, 0, s, -1, NULL, 0, 0, 0);
|
||||
|
||||
if (size > 0) {
|
||||
|
@ -104,4 +120,25 @@ char *unicodeToAnsi(const wchar_t *s, uint codePage) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
TCHAR *stringToTchar(const Common::String& s) {
|
||||
#ifndef UNICODE
|
||||
char *t = (char *)malloc(s.size() + 1);
|
||||
strcpy(t, s.c_str());
|
||||
return t;
|
||||
#else
|
||||
return ansiToUnicode(s.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
Common::String tcharToString(const TCHAR *t) {
|
||||
#ifndef UNICODE
|
||||
return t;
|
||||
#else
|
||||
char *utf8 = unicodeToAnsi(t);
|
||||
Common::String s = utf8;
|
||||
free(utf8);
|
||||
return s;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue