ReactOS 0.4.15-dev-8096-ga0eec98
registry.c File Reference
#include "iphlpapi_private.h"
Include dependency graph for registry.c:

Go to the source code of this file.

Functions

int GetLongestChildKeyName (HANDLE RegHandle)
 
LONG OpenChildKeyRead (HANDLE RegHandle, PWCHAR ChildKeyName, PHKEY ReturnHandle)
 
PWCHAR GetNthChildKeyName (HANDLE RegHandle, DWORD n)
 
void ConsumeChildKeyName (PWCHAR Name)
 
PVOID QueryRegistryValue (HANDLE RegHandle, PWCHAR ValueName, LPDWORD RegistryType, LPDWORD Length)
 
PWCHAR TerminateReadString (PWCHAR String, DWORD Length)
 
PWCHAR QueryRegistryValueString (HANDLE RegHandle, PWCHAR ValueName)
 
void ConsumeRegValueString (PWCHAR Value)
 
PWCHARQueryRegistryValueStringMulti (HANDLE RegHandle, PWCHAR ValueName)
 

Function Documentation

◆ ConsumeChildKeyName()

void ConsumeChildKeyName ( PWCHAR  Name)

Definition at line 63 of file registry.c.

63 {
64 if (Name) HeapFree( GetProcessHeap(), 0, Name );
65}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735

◆ ConsumeRegValueString()

void ConsumeRegValueString ( PWCHAR  Value)

Definition at line 140 of file registry.c.

140 {
142}
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

◆ GetLongestChildKeyName()

int GetLongestChildKeyName ( HANDLE  RegHandle)

Definition at line 3 of file registry.c.

3 {
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}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
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:3662
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
long LONG
Definition: pedump.c:60
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:78

Referenced by GetNthChildKeyName().

◆ GetNthChildKeyName()

PWCHAR GetNthChildKeyName ( HANDLE  RegHandle,
DWORD  n 
)

Definition at line 39 of file registry.c.

39 {
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}
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:2504
#define HeapAlloc
Definition: compat.h:733
int GetLongestChildKeyName(HANDLE RegHandle)
Definition: registry.c:3
GLdouble n
Definition: glext.h:7729
uint16_t * PWCHAR
Definition: typedefs.h:56
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ OpenChildKeyRead()

LONG OpenChildKeyRead ( HANDLE  RegHandle,
PWCHAR  ChildKeyName,
PHKEY  ReturnHandle 
)

Definition at line 25 of file registry.c.

27 {
29 ChildKeyName,
30 0,
32 ReturnHandle );
33}
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
#define KEY_READ
Definition: nt_native.h:1023

◆ QueryRegistryValue()

PVOID QueryRegistryValue ( HANDLE  RegHandle,
PWCHAR  ValueName,
LPDWORD  RegistryType,
LPDWORD  Length 
)

Definition at line 67 of file registry.c.

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}
BOOL Error
Definition: chkdsk.c:66
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define TRUE
Definition: types.h:120
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define REG_NONE
Definition: nt_native.h:1492
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243

Referenced by QueryRegistryValueString(), QueryRegistryValueStringMulti(), SetupDiClassNameFromGuidExW(), and SetupDiGetClassDescriptionExW().

◆ QueryRegistryValueString()

PWCHAR QueryRegistryValueString ( HANDLE  RegHandle,
PWCHAR  ValueName 
)

Definition at line 119 of file registry.c.

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}
Type
Definition: Type.h:7
PWCHAR TerminateReadString(PWCHAR String, DWORD Length)
Definition: registry.c:104
PVOID QueryRegistryValue(HANDLE RegHandle, PWCHAR ValueName, LPDWORD RegistryType, LPDWORD Length)
Definition: registry.c:67
#define DbgPrint
Definition: hal.h:12
#define REG_SZ
Definition: layer.c:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433

◆ QueryRegistryValueStringMulti()

PWCHAR * QueryRegistryValueStringMulti ( HANDLE  RegHandle,
PWCHAR  ValueName 
)

Definition at line 144 of file registry.c.

144 {
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}
ASMGENDATA Table[]
Definition: genincdata.c:61
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 memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define REG_MULTI_SZ
Definition: nt_native.h:1501

◆ TerminateReadString()

PWCHAR TerminateReadString ( PWCHAR  String,
DWORD  Length 
)

Definition at line 104 of file registry.c.

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}
#define UNICODE_NULL

Referenced by QueryRegistryValueString(), and QueryRegistryValueStringMulti().