From 8c9c9e22679478bdeabc1a9796368eae51f75a26 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 20 Feb 2016 18:52:57 +0100 Subject: [PATCH] Use right versions of Win32 functions, issue #261 --- code/nel/src/misc/dummy_window.cpp | 24 +++++++++---------- code/nel/src/misc/system_info.cpp | 2 +- code/nel/src/misc/win_displayer.cpp | 20 +++++++--------- .../driver/xaudio2/sound_driver_xaudio2.cpp | 6 ++--- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/code/nel/src/misc/dummy_window.cpp b/code/nel/src/misc/dummy_window.cpp index a0d807ac5..60fe51795 100644 --- a/code/nel/src/misc/dummy_window.cpp +++ b/code/nel/src/misc/dummy_window.cpp @@ -45,32 +45,32 @@ bool CDummyWindow::init(HINSTANCE hInstance, WNDPROC winProc) { release(); static const char *INVISIBLE_WINDOW_CLASS = "nl_invisible_wnd_class"; - WNDCLASSEX wc; - wc.cbSize = sizeof(WNDCLASSEX); - if (!GetClassInfoEx(hInstance, INVISIBLE_WINDOW_CLASS, &wc)) + WNDCLASSEXA wc; + wc.cbSize = sizeof(WNDCLASSEXA); + if (!GetClassInfoExA(hInstance, INVISIBLE_WINDOW_CLASS, &wc)) { - wc.cbSize = sizeof(WNDCLASSEX); + wc.cbSize = sizeof(WNDCLASSEXA); wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = nlDefaultWinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; - wc.hIcon = 0; - wc.hCursor = 0; - wc.hbrBackground = 0; - wc.lpszMenuName = 0; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; wc.lpszClassName = INVISIBLE_WINDOW_CLASS; - wc.hIconSm = 0; - RegisterClassEx(&wc); + wc.hIconSm = NULL; + RegisterClassExA(&wc); } - _HWnd = CreateWindow(INVISIBLE_WINDOW_CLASS, "", WS_POPUP, + _HWnd = CreateWindowA(INVISIBLE_WINDOW_CLASS, "", WS_POPUP, CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT, NULL, 0, hInstance, 0); if (_HWnd) { - if (winProc) SetWindowLongPtr(_HWnd, GWLP_WNDPROC, (LONG_PTR) winProc); + if (winProc) SetWindowLongPtrA(_HWnd, GWLP_WNDPROC, (LONG_PTR) winProc); return true; } return false; diff --git a/code/nel/src/misc/system_info.cpp b/code/nel/src/misc/system_info.cpp index 7f8a47ee1..f5a80238a 100644 --- a/code/nel/src/misc/system_info.cpp +++ b/code/nel/src/misc/system_info.cpp @@ -1062,7 +1062,7 @@ uint64 CSystemInfo::availableHDSpace (const string &filename) return (uint64)(stfs.f_bavail * stst.st_blksize); #else ULARGE_INTEGER freeSpace = {0}; - BOOL bRes = ::GetDiskFreeSpaceExA(path.c_str(), &freeSpace, NULL, NULL); + BOOL bRes = ::GetDiskFreeSpaceExW(utf8ToWide(path), &freeSpace, NULL, NULL); if (!bRes) return 0; return (uint64)freeSpace.QuadPart; diff --git a/code/nel/src/misc/win_displayer.cpp b/code/nel/src/misc/win_displayer.cpp index e81b7623e..c9e81bbb3 100644 --- a/code/nel/src/misc/win_displayer.cpp +++ b/code/nel/src/misc/win_displayer.cpp @@ -149,10 +149,9 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtr (hWnd, GWLP_USERDATA); // get the text as unicode string GetWindowTextW(cwd->_HInputEdit, wText, 20000); - ucstring ucs((ucchar*)wText); // and convert it to UTF-8 encoding. - TextSend = ucs.toUtf8(); - SendMessage (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)""); + TextSend = wideToUtf8(wText); + SendMessageA (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)""); const char *pos2 = TextSend.c_str(); string str; while (*pos2 != '\0') @@ -193,14 +192,13 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) // get the text as unicode string GetWindowTextW(cwd->_HInputEdit, wText, 20000); - ucstring ucs((ucchar*)wText); // and convert it to UTF-8 encoding - string str = ucs.toUtf8(); + string str = wideToUtf8(wText); nlassert (cwd->Log != NULL); ICommand::expand (str, *cwd->Log); SendMessageW (cwd->_HInputEdit, WM_SETTEXT, (WPARAM)0, (LPARAM)wText); - SendMessage (cwd->_HInputEdit, EM_SETSEL, str.size(), str.size()); + SendMessageA (cwd->_HInputEdit, EM_SETSEL, wcslen(wText), wcslen(wText)); return 1; } @@ -209,7 +207,7 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (pmf->wParam == VK_UP) { - CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtrW (hWnd, GWLP_USERDATA); + CWinDisplayer *cwd=(CWinDisplayer *)GetWindowLongPtrA (hWnd, GWLP_USERDATA); if (cwd->_PosInHistory > 0) cwd->_PosInHistory--; @@ -262,11 +260,11 @@ void CWinDisplayer::updateLabels () // create a button for command and label for variables if (access.value()[i].Value[0] == '@') { - access.value()[i].Hwnd = CreateWindowW (L"BUTTON", L"", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(_HWnd, GWLP_HINSTANCE), NULL); + access.value()[i].Hwnd = CreateWindowA ("BUTTON", "", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtrA(_HWnd, GWLP_HINSTANCE), NULL); } else { - access.value()[i].Hwnd = CreateWindowW (L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtr(_HWnd, GWLP_HINSTANCE), NULL); + access.value()[i].Hwnd = CreateWindowA ("STATIC", "", WS_CHILD | WS_VISIBLE | SS_SIMPLE, 0, 0, 0, 0, _HWnd, (HMENU) NULL, (HINSTANCE) GetWindowLongPtrA(_HWnd, GWLP_HINSTANCE), NULL); } SendMessageA ((HWND)access.value()[i].Hwnd, WM_SETFONT, (WPARAM)_HFont, TRUE); needResize = true; @@ -290,7 +288,7 @@ void CWinDisplayer::updateLabels () } } - SendMessage ((HWND)access.value()[i].Hwnd, WM_SETTEXT, 0, (LPARAM) n.c_str()); + SendMessageW ((HWND)access.value()[i].Hwnd, WM_SETTEXT, 0, (LPARAM) utf8ToWide(n)); access.value()[i].NeedUpdate = false; } } @@ -604,7 +602,7 @@ void CWinDisplayer::display_main () } // add the string to the edit control - SendMessageW (_HEdit, EM_REPLACESEL, FALSE, (LPARAM) str.c_str()); + SendMessageW(_HEdit, EM_REPLACESEL, FALSE, (LPARAM) str.c_str()); } // restore old selection diff --git a/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp b/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp index 3cc7a7dd2..d15f2f6aa 100644 --- a/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp +++ b/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.cpp @@ -266,8 +266,7 @@ void CSoundDriverXAudio2::getDevices(std::vector &devices) for (uint i = 0; i < deviceCount; ++i) { _XAudio2->GetDeviceDetails(i, &deviceDetails); - std::basic_string deviceNameW = deviceDetails.DisplayName; - std::string deviceName = std::string(deviceNameW.begin(), deviceNameW.end()); + std::string deviceName = wideToUtf8(deviceDetails.DisplayName); nldebug("XA2: - %s", deviceName.c_str()); devices.push_back(deviceName); } @@ -289,8 +288,7 @@ uint CSoundDriverXAudio2::getDeviceIndex(const std::string &device, XAUDIO2_DEVI for (uint i = 0; i < deviceCount; ++i) { _XAudio2->GetDeviceDetails(i, deviceDetails); - std::basic_string deviceNameW = deviceDetails->DisplayName; - std::string deviceName = std::string(deviceNameW.begin(), deviceNameW.end()); + std::string deviceName = wideToUtf8(deviceDetails->DisplayName); if (deviceName == device) return i; }