reshuffling of dlls
[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 = RegQueryInfoKeyW(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 PWCHAR ChildKeyName,
29 PHKEY ReturnHandle ) {
30 return RegOpenKeyExW( 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 PWCHAR GetNthChildKeyName( HANDLE RegHandle, DWORD n ) {
42 LONG Status;
43 int MaxAdapterName = GetLongestChildKeyName( RegHandle );
44 PWCHAR Value;
45 DWORD ValueLen;
46
47 if (MaxAdapterName == -1) {
48 RegCloseKey( RegHandle );
49 return 0;
50 }
51
52 ValueLen = MaxAdapterName;
53 Value = (PWCHAR)HeapAlloc( GetProcessHeap(), 0, MaxAdapterName );
54 Status = RegEnumKeyExW( 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( PWCHAR Name ) {
65 if (Name) HeapFree( GetProcessHeap(), 0, Name );
66 }
67
68 PWCHAR QueryRegistryValueString( HANDLE RegHandle, PWCHAR ValueName ) {
69 PWCHAR Name;
70 DWORD ReturnedSize = 0;
71
72 if (RegQueryValueExW( RegHandle, ValueName, NULL, NULL, NULL,
73 &ReturnedSize ) != 0) {
74 return 0;
75 } else {
76 Name = malloc( ReturnedSize );
77 RegQueryValueExW( RegHandle, ValueName, NULL, NULL, (PVOID)Name,
78 &ReturnedSize );
79 return Name;
80 }
81 }
82
83 void ConsumeRegValueString( PWCHAR Value ) {
84 if (Value) free(Value);
85 }
86
87 PWCHAR *QueryRegistryValueStringMulti( HANDLE RegHandle, PWCHAR ValueName ) {
88 return 0; /* FIXME if needed */
89 }
90
91 void ConsumeRegValueStringMulti( PCHAR *Value ) {
92 PCHAR *Orig = Value;
93 if (Value) {
94 while (*Value) {
95 free(*Value);
96 }
97 free(Orig);
98 }
99 }