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