From aae747c1e188909da402ed7a178b11dcda9920d2 Mon Sep 17 00:00:00 2001 From: Constantin Papizh <p.const@bk.ru> Date: Thu, 9 Jan 2020 22:39:57 +0300 Subject: [PATCH] Unicode reg path added --- src/win32/registry.c | 15 +++++++++++++++ src/win32/registry.h | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/win32/registry.c b/src/win32/registry.c index f76866f..bb8b5f9 100644 --- a/src/win32/registry.c +++ b/src/win32/registry.c @@ -27,6 +27,21 @@ char* regGetUsrPath() { return path; } +wchar_t* regWGetUsrPath() { + static wchar_t path[MAX_PATH] = {}; + if (wcslen(path) > 3) { return path; } + HKEY hKey; + const char keyPath[] = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; + LSTATUS err = RegOpenKeyExA(HKEY_CURRENT_USER, + keyPath, + 0, KEY_READ, &hKey ); + if (err != ERROR_SUCCESS) { return NULL; } + DWORD len = MAX_PATH; + err = RegGetValueW(hKey, NULL, L"Personal", RRF_RT_REG_SZ, NULL, (void*)path, &len); + RegCloseKey(hKey); + return path; +} + wchar_t* getTapGUID() { static wchar_t guid[MAX_PATH] = {}; if (wcslen(guid) > 2) { return guid; } diff --git a/src/win32/registry.h b/src/win32/registry.h index 5dea305..9299ca1 100644 --- a/src/win32/registry.h +++ b/src/win32/registry.h @@ -14,7 +14,8 @@ wchar_t* getTapGUID(); wchar_t* getTapName(); wchar_t* getUserSID(LPCWSTR homePath); -char* regGetUsrPath(); +wchar_t* regWGetUsrPath(); +char* regGetUsrPath(); #ifdef __cplusplus } -- GitLab