ReactOS  0.4.14-dev-293-g2b39b42
registry.c
Go to the documentation of this file.
1 #include "iphlpapi_private.h"
2 
4  LONG Status;
5  DWORD MaxAdapterName;
6 
8  NULL,
9  NULL,
10  NULL,
11  NULL,
12  &MaxAdapterName,
13  NULL,
14  NULL,
15  NULL,
16  NULL,
17  NULL,
18  NULL);
19  if (Status == ERROR_SUCCESS)
20  return MaxAdapterName + 1;
21  else
22  return -1;
23 }
24 
26  PWCHAR ChildKeyName,
27  PHKEY ReturnHandle ) {
28  return RegOpenKeyExW( RegHandle,
29  ChildKeyName,
30  0,
31  KEY_READ,
32  ReturnHandle );
33 }
34 
35 /*
36  * Yields a malloced value that must be freed.
37  */
38 
40  LONG Status;
41  int MaxAdapterName = GetLongestChildKeyName( RegHandle );
42  PWCHAR Value;
43  DWORD ValueLen;
44 
45  if (MaxAdapterName == -1)
46  return 0;
47 
48  ValueLen = MaxAdapterName;
49  Value = (PWCHAR)HeapAlloc( GetProcessHeap(), 0, MaxAdapterName * sizeof(WCHAR) );
50  if (!Value) return 0;
51 
52  Status = RegEnumKeyExW( RegHandle, n, Value, &ValueLen,
53  NULL, NULL, NULL, NULL );
54  if (Status != ERROR_SUCCESS) {
56  return 0;
57  } else {
58  Value[ValueLen] = 0;
59  return Value;
60  }
61 }
62 
64  if (Name) HeapFree( GetProcessHeap(), 0, Name );
65 }
66 
68 {
69  PVOID ReadValue = NULL;
70  DWORD Error;
71 
72  *Length = 0;
73  *RegistryType = REG_NONE;
74 
75  while (TRUE)
76  {
77  Error = RegQueryValueExW(RegHandle, ValueName, NULL, RegistryType, ReadValue, Length);
78  if (Error == ERROR_SUCCESS)
79  {
80  if (ReadValue) break;
81  }
82  else if (Error == ERROR_MORE_DATA)
83  {
84  HeapFree(GetProcessHeap(), 0, ReadValue);
85  }
86  else break;
87 
88  ReadValue = HeapAlloc(GetProcessHeap(), 0, *Length);
89  if (!ReadValue) return NULL;
90  }
91 
92  if (Error != ERROR_SUCCESS)
93  {
94  if (ReadValue) HeapFree(GetProcessHeap(), 0, ReadValue);
95 
96  *Length = 0;
97  *RegistryType = REG_NONE;
98  ReadValue = NULL;
99  }
100 
101  return ReadValue;
102 }
103 
105 {
106  PWCHAR TerminatedString;
107 
108  TerminatedString = HeapAlloc(GetProcessHeap(), 0, Length + sizeof(WCHAR));
109  if (TerminatedString == NULL)
110  return NULL;
111 
112  memcpy(TerminatedString, String, Length);
113 
114  TerminatedString[Length / sizeof(WCHAR)] = UNICODE_NULL;
115 
116  return TerminatedString;
117 }
118 
120 {
121  PWCHAR String, TerminatedString;
122  DWORD Type, Length;
123 
125  if (!String) return NULL;
126  if (Type != REG_SZ)
127  {
128  DbgPrint("Type mismatch for %S (%d != %d)\n", ValueName, Type, REG_SZ);
129  //HeapFree(GetProcessHeap(), 0, String);
130  //return NULL;
131  }
132 
133  TerminatedString = TerminateReadString(String, Length);
135  if (!TerminatedString) return NULL;
136 
137  return TerminatedString;
138 }
139 
141  if (Value) HeapFree(GetProcessHeap(), 0, Value);
142 }
143 
145  PWCHAR String, TerminatedString, Tmp;
146  PWCHAR *Table;
147  DWORD Type, Length, i, j;
148 
150  if (!String) return NULL;
151  if (Type != REG_MULTI_SZ)
152  {
153  DbgPrint("Type mismatch for %S (%d != %d)\n", ValueName, Type, REG_MULTI_SZ);
154  //HeapFree(GetProcessHeap(), 0, String);
155  //return NULL;
156  }
157 
158  TerminatedString = TerminateReadString(String, Length);
160  if (!TerminatedString) return NULL;
161 
162  for (Tmp = TerminatedString, i = 0; *Tmp; Tmp++, i++) while (*Tmp) Tmp++;
163 
164  Table = HeapAlloc(GetProcessHeap(), 0, (i + 1) * sizeof(PWCHAR));
165  if (!Table)
166  {
167  HeapFree(GetProcessHeap(), 0, TerminatedString);
168  return NULL;
169  }
170 
171  for (Tmp = TerminatedString, j = 0; *Tmp; Tmp++, j++)
172  {
173  PWCHAR Orig = Tmp;
174 
175  for (i = 0; *Tmp; i++, Tmp++);
176 
177  Table[j] = HeapAlloc(GetProcessHeap(), 0, i * sizeof(WCHAR));
178  memcpy(Table[j], Orig, i * sizeof(WCHAR));
179  }
180 
181  Table[j] = NULL;
182 
183  HeapFree(GetProcessHeap(), 0, TerminatedString);
184 
185  return Table;
186 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
ASMGENDATA Table[]
Definition: genincdata.c:61
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DbgPrint
Definition: loader.c:25
void ConsumeRegValueString(PWCHAR Value)
Definition: registry.c:140
#define KEY_READ
Definition: nt_native.h:1023
GLdouble n
Definition: glext.h:7729
PWCHAR TerminateReadString(PWCHAR String, DWORD Length)
Definition: registry.c:104
static WCHAR String[]
Definition: stringtable.c:55
uint16_t * PWCHAR
Definition: typedefs.h:54
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define UNICODE_NULL
long LONG
Definition: pedump.c:60
PWCHAR QueryRegistryValueString(HANDLE RegHandle, PWCHAR ValueName)
Definition: registry.c:119
#define REG_MULTI_SZ
Definition: nt_native.h:1501
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:76
PVOID QueryRegistryValue(HANDLE RegHandle, PWCHAR ValueName, LPDWORD RegistryType, LPDWORD Length)
Definition: registry.c:67
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
PWCHAR * QueryRegistryValueStringMulti(HANDLE RegHandle, PWCHAR ValueName)
Definition: registry.c:144
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
void ConsumeChildKeyName(PWCHAR Name)
Definition: registry.c:63
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
LONG OpenChildKeyRead(HANDLE RegHandle, PWCHAR ChildKeyName, PHKEY ReturnHandle)
Definition: registry.c:25
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
int GetLongestChildKeyName(HANDLE RegHandle)
Definition: registry.c:3
#define ERROR_MORE_DATA
Definition: dderror.h:13
Status
Definition: gdiplustypes.h:24
LONG WINAPI RegQueryValueExW(IN HKEY hKey, IN LPCWSTR lpValueName, IN PULONG lpReserved, OUT PULONG lpType OPTIONAL, OUT PUCHAR lpData OPTIONAL, IN OUT PULONG lpcbData OPTIONAL)
Definition: registry.c:862
PWCHAR GetNthChildKeyName(HANDLE RegHandle, DWORD n)
Definition: registry.c:39
uint32_t * LPDWORD
Definition: typedefs.h:57
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
#define REG_NONE
Definition: nt_native.h:1492
#define HeapFree(x, y, z)
Definition: compat.h:394
#define REG_SZ
Definition: layer.c:22