ReactOS 0.4.15-dev-5664-g3bf4ef6
registry.c
Go to the documentation of this file.
1#include "iphlpapi_private.h"
2
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 ) {
29 ChildKeyName,
30 0,
32 ReturnHandle );
33}
34
35/*
36 * Yields a malloced value that must be freed.
37 */
38
41 int MaxAdapterName = GetLongestChildKeyName( RegHandle );
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;
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;
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
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}
Type
Definition: Type.h:7
BOOL Error
Definition: chkdsk.c:66
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
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
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:3690
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4121
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
PWCHAR QueryRegistryValueString(HANDLE RegHandle, PWCHAR ValueName)
Definition: registry.c:119
PWCHAR TerminateReadString(PWCHAR String, DWORD Length)
Definition: registry.c:104
LONG OpenChildKeyRead(HANDLE RegHandle, PWCHAR ChildKeyName, PHKEY ReturnHandle)
Definition: registry.c:25
int GetLongestChildKeyName(HANDLE RegHandle)
Definition: registry.c:3
void ConsumeChildKeyName(PWCHAR Name)
Definition: registry.c:63
PWCHAR * QueryRegistryValueStringMulti(HANDLE RegHandle, PWCHAR ValueName)
Definition: registry.c:144
PVOID QueryRegistryValue(HANDLE RegHandle, PWCHAR ValueName, LPDWORD RegistryType, LPDWORD Length)
Definition: registry.c:67
PWCHAR GetNthChildKeyName(HANDLE RegHandle, DWORD n)
Definition: registry.c:39
void ConsumeRegValueString(PWCHAR Value)
Definition: registry.c:140
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
ASMGENDATA Table[]
Definition: genincdata.c:61
GLdouble n
Definition: glext.h:7729
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
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 DbgPrint
Definition: hal.h:12
#define REG_SZ
Definition: layer.c:22
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define KEY_READ
Definition: nt_native.h:1023
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define REG_NONE
Definition: nt_native.h:1492
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
long LONG
Definition: pedump.c:60
uint32_t * LPDWORD
Definition: typedefs.h:59
uint16_t * PWCHAR
Definition: typedefs.h:56
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:78
__wchar_t WCHAR
Definition: xmlstorage.h:180