No more ick tabs.
[reactos.git] / reactos / lib / iphlpapi / registry.c
1 #include "iphlpapi_private.h"
2
3 #include "debug.h"
4
5 int GetLongestChildKeyName( HANDLE RegHandle ) {
6 LONG Status;
7 DWORD MaxAdapterName;
8
9 Status = RegQueryInfoKeyA(RegHandle,
10 NULL,
11 NULL,
12 NULL,
13 NULL,
14 &MaxAdapterName,
15 NULL,
16 NULL,
17 NULL,
18 NULL,
19 NULL,
20 NULL);
21 if (Status == ERROR_SUCCESS)
22 return MaxAdapterName + 1;
23 else
24 return -1;
25 }
26
27 LONG OpenChildKeyRead( HANDLE RegHandle,
28 PCHAR ChildKeyName,
29 PHKEY ReturnHandle ) {
30 return RegOpenKeyExA( RegHandle,
31 ChildKeyName,
32 0,
33 KEY_READ,
34 ReturnHandle );
35 }
36
37 /*
38 * Yields a malloced value that must be freed.
39 */
40
41 PCHAR GetNthChildKeyName( HANDLE RegHandle, DWORD n ) {
42 LONG Status;
43 int MaxAdapterName = GetLongestChildKeyName( RegHandle );
44 PCHAR Value;
45 DWORD ValueLen;
46
47 if (MaxAdapterName == -1) {
48 RegCloseKey( RegHandle );
49 return 0;
50 }
51
52 ValueLen = MaxAdapterName;
53 Value = (PCHAR)HeapAlloc( GetProcessHeap(), 0, MaxAdapterName );
54 Status = RegEnumKeyExA( RegHandle, n, Value, &ValueLen,
55 NULL, NULL, NULL, NULL );
56 if (Status != ERROR_SUCCESS)
57 return 0;
58 else {
59 Value[ValueLen] = 0;
60 return Value;
61 }
62 }
63
64 void ConsumeChildKeyName( PCHAR Name ) {
65 if (Name) HeapFree( GetProcessHeap(), 0, Name );
66 }
67
68 PCHAR QueryRegistryValueString( HANDLE RegHandle, PCHAR ValueName ) {
69 PCHAR Name;
70 DWORD ReturnedSize = 0;
71
72 if (RegQueryValueExA( RegHandle, ValueName, NULL, NULL, NULL,
73 &ReturnedSize ) != 0)
74 return 0;
75 else {
76 Name = malloc( (ReturnedSize + 1) * sizeof(WCHAR) );
77 RegQueryValueExA( RegHandle, ValueName, NULL, NULL, (PVOID)Name,
78 &ReturnedSize );
79 Name[ReturnedSize] = 0;
80 return Name;
81 }
82 }
83
84 void ConsumeRegValueString( PCHAR Value ) {
85 if (Value) free(Value);
86 }
87
88 PWCHAR *QueryRegistryValueStringMulti( HANDLE RegHandle, PWCHAR ValueName ) {
89 return 0; /* FIXME if needed */
90 }
91
92 void ConsumeRegValueStringMulti( PCHAR *Value ) {
93 PCHAR *Orig = Value;
94 if (Value) {
95 while (*Value) {
96 free(*Value);
97 }
98 free(Orig);
99 }
100 }