summary refs log tree commit diff stats
path: root/src/gtk2-prefs/win32util.cpp
blob: 79cab17d49c49ae2f1d079f9a8003e20e5f528ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/***************************************************************************
                          win32util.cpp  -  description
                             -------------------
    begin                : Tue Jan 14 2003
    copyright            : (C) 2003 by Alex Shaduri
    email                : alex_sh@land.ru
 ***************************************************************************/

#ifdef _WIN32

#include <string>
#include "sys_win32.h"
#include "win32util.h"





std::string win32_get_registry_value_string(HKEY base, const std::string& keydir, const std::string& key)
{

	HKEY reg_key = NULL;
	DWORD type;
	DWORD nbytes;
	char* result = NULL;
//HKEY_CURRENT_USER
	nbytes = 0;
	if ( RegOpenKeyEx ( base, keydir.c_str(), 0, KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS
			&& RegQueryValueEx (reg_key, key.c_str(), 0, &type, NULL, &nbytes) == ERROR_SUCCESS ) {
		result = (char*)malloc(nbytes + 1);
		RegQueryValueEx (reg_key,  key.c_str(), 0, &type, (BYTE*)result, &nbytes);
		result[nbytes] = '\0';
	}

	if (reg_key != NULL)
		RegCloseKey (reg_key);

	std::string ret = "";

	if (result) {
		ret = result;
	}

	return ret;

}




void win32_set_registry_value_string(HKEY base, const std::string& keydir, const std::string& key, const std::string& value)
{

	HKEY reg_key = NULL;
	DWORD nbytes;

	nbytes = value.length() + 1;

	if ( RegOpenKeyEx ( base, keydir.c_str(), 0, KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS) {
		RegSetValueEx (reg_key,  key.c_str(), 0, REG_SZ, (const BYTE*)(value.c_str()), nbytes);
	}

	if (reg_key != NULL)
		RegCloseKey (reg_key);

}







#endif