libobs: Add wrapper function to query Windows registry

This commit is contained in:
Ryan Foster 2017-10-09 02:29:34 -04:00
parent a76b919c6e
commit 0759eeb5da
3 changed files with 62 additions and 0 deletions

View File

@ -83,6 +83,7 @@ if(WIN32)
util/platform-windows.c)
set(libobs_PLATFORM_HEADERS
util/threading-windows.h
util/windows/win-registry.h
util/windows/win-version.h
util/windows/ComPtr.hpp
util/windows/CoTaskMemPtr.hpp

View File

@ -26,6 +26,7 @@
#include "platform.h"
#include "darray.h"
#include "dstr.h"
#include "windows/win-registry.h"
#include "windows/win-version.h"
#include "../../deps/w32-pthreads/pthread.h"
@ -800,6 +801,28 @@ bool is_64_bit_windows(void)
#endif
}
void get_reg_dword(HKEY hkey, LPCWSTR sub_key, LPCWSTR value_name,
struct reg_dword *info)
{
struct reg_dword reg = {0};
HKEY key;
LSTATUS status;
status = RegOpenKeyEx(hkey, sub_key, 0, KEY_READ, &key);
if (status != ERROR_SUCCESS)
return;
reg.size = sizeof(reg.return_value);
reg.status = RegQueryValueExW(key, value_name, NULL, NULL,
(LPBYTE)&reg.return_value, &reg.size);
RegCloseKey(key);
*info = reg;
}
#define WINVER_REG_KEY L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
void get_win_ver(struct win_version_info *info)

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2015 Hugh Bailey <obs.jim@gmail.com>
* Copyright (c) 2017 Ryan Foster <RytoEX@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include <windows.h>
#include "../c99defs.h"
#ifdef __cplusplus
extern "C" {
#endif
struct reg_dword {
LSTATUS status;
DWORD size;
DWORD return_value;
};
EXPORT void get_reg_dword(HKEY hkey, LPCWSTR sub_key, LPCWSTR value_name,
struct reg_dword *info);
#ifdef __cplusplus
}
#endif