13
0

Consolidate code: add library method to query Windows registry

This commit is contained in:
Robin Gareus 2020-10-24 03:56:47 +02:00
parent 5d193f7638
commit 8852069ead
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 28 additions and 0 deletions

View File

@ -38,6 +38,8 @@ namespace PBD {
*/
LIBPBD_API std::string get_win_special_folder_path (int csidl);
LIBPBD_API bool windows_query_registry (const char *regkey, const char *regval, std::string &rv);
}
#endif /* __libpbd_windows_special_dirs_h__ */

View File

@ -20,6 +20,7 @@
#include <shlobj.h>
#include <winreg.h>
#include <glib.h>
#include "shlobj.h"
#include "pbd/windows_special_dirs.h"
@ -47,3 +48,28 @@ PBD::get_win_special_folder_path (int csidl)
return std::string();
}
bool
PBD::windows_query_registry (const char *regkey, const char *regval, std::string &rv)
{
HKEY key;
DWORD size = PATH_MAX;
char tmp[PATH_MAX+1];
if ( (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ, &key))
&& (ERROR_SUCCESS == RegQueryValueExA (key, regval, 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
)
{
rv = Glib::locale_to_utf8 (tmp);
return true;
}
if ( (ERROR_SUCCESS == RegOpenKeyExA (HKEY_LOCAL_MACHINE, regkey, 0, KEY_READ | KEY_WOW64_32KEY, &key))
&& (ERROR_SUCCESS == RegQueryValueExA (key, regval, 0, NULL, reinterpret_cast<LPBYTE>(tmp), &size))
)
{
rv = Glib::locale_to_utf8 (tmp);
return true;
}
return false;
}