@@ -79,6 +79,14 @@ inline bool win32_set_registry_value_string(HKEY base,
7979 const std::string& keydir, const std::string& key, const std::string& value);
8080
8181
82+ // / Get registry value as a DWORD.
83+ // / Base may be e.g. HKEY_CURRENT_USER.
84+ // / Note that this works only with REG_DWORD types.
85+ // / False is returned for all other types.
86+ inline bool win32_get_registry_value_dword (HKEY base,
87+ const std::string& keydir, const std::string& key, DWORD & put_here);
88+
89+
8290// / Redirect stdout and stderr to console window (if open). Requires winxp (at compile-time).
8391// / \param create_if_none if true, create a new console if none was found and attach to it.
8492// / \return false if failed or unsupported.
@@ -340,6 +348,49 @@ inline bool win32_set_registry_value_string(HKEY base,
340348
341349
342350
351+ // Get registry value as a DWORD.
352+ // Note that this works only with REG_DWORD types.
353+ inline bool win32_get_registry_value_dword (HKEY base,
354+ const std::string& keydir, const std::string& key, DWORD & put_here)
355+ {
356+ std::wstring wkeydir = win32_utf8_to_utf16 (keydir);
357+ if (wkeydir.empty ())
358+ return false ;
359+
360+ HKEY reg_key = nullptr ;
361+ bool open_status = (RegOpenKeyExW (base, wkeydir.c_str (), 0 , KEY_QUERY_VALUE , ®_key) == ERROR_SUCCESS );
362+
363+ if (!open_status)
364+ return false ;
365+
366+ bool ok = false ;
367+ std::wstring wkey = win32_utf8_to_utf16 (key, &ok);
368+ if (!ok) { // conversion error. Note that an empty string is not an error.
369+ if (reg_key)
370+ RegCloseKey (reg_key);
371+ return false ;
372+ }
373+
374+ DWORD type = 0 ;
375+ DWORD value = 0 ;
376+ DWORD nbytes = sizeof (DWORD );
377+ bool status = (RegQueryValueExW (reg_key, wkey.c_str (), nullptr , &type,
378+ reinterpret_cast <BYTE *>(&value), &nbytes) == ERROR_SUCCESS );
379+
380+ if (status && type == REG_DWORD ) {
381+ put_here = value;
382+ } else {
383+ status = false ;
384+ }
385+
386+ if (reg_key)
387+ RegCloseKey (reg_key);
388+
389+ return status;
390+ }
391+
392+
393+
343394// Redirect stdout and stderr to console window (if open).
344395inline bool win32_redirect_stdio_to_console (bool create_if_none)
345396{
0 commit comments