Sync with trunk head
[reactos.git] / dll / win32 / 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 return 0;
49
50 ValueLen = MaxAdapterName;
51 Value = (PWCHAR)HeapAlloc( GetProcessHeap(), 0, MaxAdapterName * sizeof(WCHAR) );
52 if (!Value) return 0;
53
54 Status = RegEnumKeyExW( RegHandle, n, Value, &ValueLen,
55 NULL, NULL, NULL, NULL );
56 if (Status != ERROR_SUCCESS) {
57 HeapFree(GetProcessHeap(), 0, Value);
58 return 0;
59 } else {
60 Value[ValueLen] = 0;
61 return Value;
62 }
63 }
64
65 void ConsumeChildKeyName( PWCHAR Name ) {
66 if (Name) HeapFree( GetProcessHeap(), 0, Name );
67 }
68
69 PWCHAR QueryRegistryValueString( HANDLE RegHandle, PWCHAR ValueName ) {
70 PWCHAR Name;
71 DWORD ReturnedSize = 0;
72
73 if (RegQueryValueExW( RegHandle, ValueName, NULL, NULL, NULL,
74 &ReturnedSize ) != 0) {
75 return 0;
76 } else {
77 Name = malloc( ReturnedSize);
78 RegQueryValueExW( RegHandle, ValueName, NULL, NULL, (PVOID)Name,
79 &ReturnedSize );
80 return Name;
81 }
82 }
83
84 void ConsumeRegValueString( PWCHAR Value ) {
85 if (Value) free(Value);
86 }
87
88 PWCHAR *QueryRegistryValueStringMulti( HANDLE RegHandle, PWCHAR ValueName ) {
89 return 0; /* FIXME if needed */
90 }