ReactOS  0.4.14-dev-317-g96040ec
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:395
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ ConsumeRegValueString()

void ConsumeRegValueString ( PWCHAR  Value)

Definition at line 140 of file registry.c.

140  {
141  if (Value) HeapFree(GetProcessHeap(), 0, Value);
142 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define GetProcessHeap()
Definition: compat.h:395
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ GetLongestChildKeyName()

int GetLongestChildKeyName ( HANDLE  RegHandle)

Definition at line 3 of file registry.c.

3  {
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 }
#define ERROR_SUCCESS
Definition: deptool.c:10
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:76
unsigned long DWORD
Definition: ntddk_ex.h:95
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
Status
Definition: gdiplustypes.h:24

Referenced by GetNthChildKeyName().

◆ GetNthChildKeyName()

PWCHAR GetNthChildKeyName ( HANDLE  RegHandle,
DWORD  n 
)

Definition at line 39 of file registry.c.

39  {
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 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2343
#define ERROR_SUCCESS
Definition: deptool.c:10
GLdouble n
Definition: glext.h:7729
uint16_t * PWCHAR
Definition: typedefs.h:54
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:76
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
int GetLongestChildKeyName(HANDLE RegHandle)
Definition: registry.c:3
Status
Definition: gdiplustypes.h:24
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 HeapFree(x, y, z)
Definition: compat.h:394

◆ OpenChildKeyRead()

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

Definition at line 25 of file registry.c.

27  {
28  return RegOpenKeyExW( RegHandle,
29  ChildKeyName,
30  0,
31  KEY_READ,
32  ReturnHandle );
33 }
#define KEY_READ
Definition: nt_native.h:1023
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:76
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366

◆ QueryRegistryValue()

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

Definition at line 67 of file registry.c.

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 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
smooth NULL
Definition: ftsmooth.c:416
_In_opt_ PETWENABLECALLBACK _In_opt_ PVOID _Out_ PREGHANDLE RegHandle
Definition: wmifuncs.h:76
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
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
#define ERROR_MORE_DATA
Definition: dderror.h:13
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
#define REG_NONE
Definition: nt_native.h:1492
#define HeapFree(x, y, z)
Definition: compat.h:394

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;
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 }
Type
Definition: Type.h:6
#define DbgPrint
Definition: loader.c:25
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
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
#define GetProcessHeap()
Definition: compat.h:395
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define HeapFree(x, y, z)
Definition: compat.h:394
#define REG_SZ
Definition: layer.c:22

◆ 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
Type
Definition: Type.h:6
#define DbgPrint
Definition: loader.c:25
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 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)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ 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 }
static WCHAR String[]
Definition: stringtable.c:55
uint16_t * PWCHAR
Definition: typedefs.h:54
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by QueryRegistryValueString(), and QueryRegistryValueStringMulti().