1 /**
2 * FreeRDP: A Remote Desktop Protocol Implementation
3 * FreeRDP Windows Server
4 *
5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <winpr/tchar.h>
25 #include <winpr/windows.h>
26
27 #include "wf_settings.h"
28
wf_settings_read_dword(HKEY key,LPCSTR subkey,LPTSTR name,DWORD * value)29 BOOL wf_settings_read_dword(HKEY key, LPCSTR subkey, LPTSTR name, DWORD* value)
30 {
31 HKEY hKey;
32 LONG status;
33 DWORD dwType;
34 DWORD dwSize;
35 DWORD dwValue;
36
37 status = RegOpenKeyExA(key, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
38
39 if (status == ERROR_SUCCESS)
40 {
41 dwSize = sizeof(DWORD);
42
43 status = RegQueryValueEx(hKey, name, NULL, &dwType, (BYTE*)&dwValue, &dwSize);
44
45 if (status == ERROR_SUCCESS)
46 *value = dwValue;
47
48 RegCloseKey(hKey);
49
50 return (status == ERROR_SUCCESS) ? TRUE : FALSE;
51 }
52
53 return FALSE;
54 }
55
wf_settings_read_string_ascii(HKEY key,LPCSTR subkey,LPTSTR name,char ** value)56 BOOL wf_settings_read_string_ascii(HKEY key, LPCSTR subkey, LPTSTR name, char** value)
57 {
58 HKEY hKey;
59 int length;
60 LONG status;
61 DWORD dwType;
62 DWORD dwSize;
63 char* strA;
64 TCHAR* strX = NULL;
65
66 status = RegOpenKeyExA(key, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
67
68 if (status != ERROR_SUCCESS)
69 return FALSE;
70
71 status = RegQueryValueEx(hKey, name, NULL, &dwType, NULL, &dwSize);
72
73 if (status == ERROR_SUCCESS)
74 {
75 strX = (LPTSTR)malloc(dwSize + sizeof(TCHAR));
76 if (!strX)
77 return FALSE;
78 status = RegQueryValueEx(hKey, name, NULL, &dwType, (BYTE*)strX, &dwSize);
79
80 if (status != ERROR_SUCCESS)
81 {
82 free(strX);
83 RegCloseKey(hKey);
84 return FALSE;
85 }
86 }
87
88 if (strX)
89 {
90 #ifdef UNICODE
91 length = WideCharToMultiByte(CP_UTF8, 0, strX, lstrlenW(strX), NULL, 0, NULL, NULL);
92 strA = (char*)malloc(length + 1);
93 WideCharToMultiByte(CP_UTF8, 0, strX, lstrlenW(strX), strA, length, NULL, NULL);
94 strA[length] = '\0';
95 free(strX);
96 #else
97 strA = (char*)strX;
98 #endif
99 *value = strA;
100 return TRUE;
101 }
102
103 return FALSE;
104 }
105