2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2021 the Claws Mail team and Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 gboolean
reg_set_value(HKEY root
,
35 ret
= RegCreateKeyEx(root
, subkey
, 0, NULL
, REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
, &key
, NULL
);
36 if (ret
!= ERROR_SUCCESS
) {
37 tmp
= g_win32_error_message(ret
);
38 debug_print("RegCreateKeyEx %p \"%s\" had error: \"%s\"\n", root
, subkey
, tmp
);
43 ret
= RegSetValueEx(key
, value
, 0, type
, data
, data_size
);
44 if (ret
!= ERROR_SUCCESS
) {
45 tmp
= g_win32_error_message(ret
);
46 debug_print("RegSetValueEx %p \"%s\" had error: \"%s\"\n", root
, subkey
, tmp
);
51 return (ret
== ERROR_SUCCESS
);
54 gboolean
write_w32_registry_string(HKEY root
,
59 return reg_set_value(root
, subkey
, value
, REG_SZ
, (BYTE
*)data
, strlen(data
) + 1);
62 gboolean
write_w32_registry_dword(HKEY root
,
67 return reg_set_value(root
, subkey
, value
, REG_DWORD
, (BYTE
*)&data
, sizeof(DWORD
));
70 gchar
*read_w32_registry_string(HKEY root
, const gchar
*subkey
, const gchar
*value
)
82 ret
= RegOpenKeyEx(root
, subkey
, 0, KEY_READ
, &hkey
);
83 if (ret
!= ERROR_SUCCESS
) {
84 tmp
= g_win32_error_message(ret
);
85 debug_print("RegOpenKeyEx %p \"%s\" had error: \"%s\"\n", root
, subkey
, tmp
);
90 // Get the needed buffer size
91 ret
= RegQueryValueEx(hkey
, value
, 0, &type
, NULL
, &data_size
);
92 if (ret
!= ERROR_SUCCESS
) {
93 tmp
= g_win32_error_message(ret
);
94 debug_print("RegQueryValueEx %p \"%s\" \"%s\" had error: \"%s\" when getting buffer size\n",
95 root
, subkey
, value
, tmp
);
99 } else if (type
!= REG_SZ
) {
100 debug_print("RegQueryValueEx %p \"%s\" \"%s\" returned type %lu instead of REG_SZ\n",
101 root
, subkey
, value
, type
);
104 } else if (data_size
== 0) {
105 debug_print("RegQueryValueEx %p \"%s\" \"%s\" returned data size 0\n",
106 root
, subkey
, value
);
111 // The raw value is not necessarily NUL-terminated
112 data
= g_malloc(data_size
+ 1);
114 ret
= RegQueryValueEx(hkey
, value
, 0, NULL
, data
, &data_size
);
115 if (ret
== ERROR_SUCCESS
) {
116 data
[data_size
] = '\0';
118 tmp
= g_win32_error_message(ret
);
119 debug_print("RegQueryValueEx %p \"%s\" \"%s\" had error: \"%s\"\n",
120 root
, subkey
, value
, tmp
);
128 return (gchar
*)data
;