From 9b53b815f7eefa9e2c46e42b988d0293408e6061 Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 21 Feb 2016 20:30:16 +0100 Subject: [PATCH] Merge with develop --- code/nel/src/misc/system_utils.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/code/nel/src/misc/system_utils.cpp b/code/nel/src/misc/system_utils.cpp index 7ea9ad544..4b59817e0 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -319,9 +319,9 @@ string CSystemUtils::getRegKey(const string &Entry) { DWORD dwType = 0L; DWORD dwSize = KeyMaxLength; - unsigned char Buffer[KeyMaxLength]; + wchar_t Buffer[KeyMaxLength]; - if (RegQueryValueExW(hkey, utf8ToWide(Entry), NULL, &dwType, Buffer, &dwSize) != ERROR_SUCCESS) + if (RegQueryValueExW(hkey, utf8ToWide(Entry), NULL, &dwType, (LPBYTE)Buffer, &dwSize) != ERROR_SUCCESS) { nlwarning("Can't get the reg key '%s'", Entry.c_str()); } @@ -329,6 +329,7 @@ string CSystemUtils::getRegKey(const string &Entry) { ret = wideToUtf8(Buffer); } + RegCloseKey(hkey); } else @@ -346,11 +347,13 @@ bool CSystemUtils::setRegKey(const string &ValueName, const string &Value) HKEY hkey; DWORD dwDisp; - wchar_t nstr[] = { 0x00 }; - if (RegCreateKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, nstr, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS) + if (RegCreateKeyExW(HKEY_CURRENT_USER, utf8ToWide(RootKey), 0, L"", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwDisp) == ERROR_SUCCESS) { ucstring utf16Value = ucstring::makeFromUtf8(Value); + + // we must use the real Unicode string size in bytes DWORD size = (utf16Value.length() + 1) * 2; + if (RegSetValueExW(hkey, utf8ToWide(ValueName), 0L, REG_SZ, (const BYTE *)utf16Value.c_str(), size) == ERROR_SUCCESS) res = true; RegCloseKey(hkey);