FreeRDP
wf_settings.c
1 
20 #include <freerdp/config.h>
21 
22 #include <winpr/tchar.h>
23 #include <winpr/windows.h>
24 
25 #include "wf_settings.h"
26 
27 BOOL wf_settings_read_dword(HKEY key, LPCSTR subkey, LPTSTR name, DWORD* value)
28 {
29  HKEY hKey;
30  LONG status;
31  DWORD dwType;
32  DWORD dwSize;
33  DWORD dwValue;
34 
35  status = RegOpenKeyExA(key, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
36 
37  if (status == ERROR_SUCCESS)
38  {
39  dwSize = sizeof(DWORD);
40 
41  status = RegQueryValueEx(hKey, name, NULL, &dwType, (BYTE*)&dwValue, &dwSize);
42 
43  if (status == ERROR_SUCCESS)
44  *value = dwValue;
45 
46  RegCloseKey(hKey);
47 
48  return (status == ERROR_SUCCESS) ? TRUE : FALSE;
49  }
50 
51  return FALSE;
52 }
53 
54 BOOL wf_settings_read_string_ascii(HKEY key, LPCSTR subkey, LPTSTR name, char** value)
55 {
56  HKEY hKey;
57  int length;
58  LONG status;
59  DWORD dwType;
60  DWORD dwSize;
61  char* strA;
62  TCHAR* strX = NULL;
63 
64  status = RegOpenKeyExA(key, subkey, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
65 
66  if (status != ERROR_SUCCESS)
67  return FALSE;
68 
69  status = RegQueryValueEx(hKey, name, NULL, &dwType, NULL, &dwSize);
70 
71  if (status == ERROR_SUCCESS)
72  {
73  strX = (LPTSTR)malloc(dwSize + sizeof(TCHAR));
74  if (!strX)
75  return FALSE;
76  status = RegQueryValueEx(hKey, name, NULL, &dwType, (BYTE*)strX, &dwSize);
77 
78  if (status != ERROR_SUCCESS)
79  {
80  free(strX);
81  RegCloseKey(hKey);
82  return FALSE;
83  }
84  }
85 
86  if (strX)
87  {
88 #ifdef UNICODE
89  length = WideCharToMultiByte(CP_UTF8, 0, strX, lstrlenW(strX), NULL, 0, NULL, NULL);
90  strA = (char*)malloc(length + 1);
91  WideCharToMultiByte(CP_UTF8, 0, strX, lstrlenW(strX), strA, length, NULL, NULL);
92  strA[length] = '\0';
93  free(strX);
94 #else
95  strA = (char*)strX;
96 #endif
97  *value = strA;
98  return TRUE;
99  }
100 
101  return FALSE;
102 }