f43179a5e72fec358a512228cfeac6bb1531a499
[reactos.git] / rostests / tests / regqueryvalue / regqueryvalue.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <wchar.h>
5 #include <windows.h>
6
7 int main( int argc, char **argv ) {
8 ULONG ResultSize;
9 PWCHAR WcharResult;
10 WCHAR ValueNameWC[100];
11 PCHAR CharResult;
12 HKEY RegKey;
13 int i;
14
15 if( argc < 2 ) {
16 printf( "Usage: regqueryvalue [key] [value]\n" );
17 printf( "Returns an HKEY_LOCAL_MACHINE value from the given key.\n" );
18 return 1;
19 }
20
21 if ( RegOpenKeyExA( HKEY_LOCAL_MACHINE, argv[1], 0, KEY_READ, &RegKey )
22 != 0 ) {
23 printf( "Could not open key %s\n", argv[1] );
24 return 2;
25 }
26
27 for( i = 0; argv[2][i]; i++ ) ValueNameWC[i] = argv[2][i];
28 ValueNameWC[i] = 0;
29
30 if(RegQueryValueExW( RegKey, ValueNameWC, NULL, NULL, NULL, &ResultSize )
31 != 0) {
32 printf( "The value %S does not exist.\n", ValueNameWC );
33 return 5;
34 }
35
36 WcharResult = malloc( (ResultSize + 1) * sizeof(WCHAR) );
37
38 if( !WcharResult ) {
39 printf( "Could not alloc %d wchars\n", (int)(ResultSize + 1) );
40 return 6;
41 }
42
43 RegQueryValueExW( RegKey, ValueNameWC, NULL, NULL, (LPBYTE)WcharResult,
44 &ResultSize );
45
46 printf( "wchar Value: %S\n", WcharResult );
47 fflush( stdout );
48
49 RegQueryValueExA( RegKey, argv[2], NULL, NULL, NULL, &ResultSize );
50
51 CharResult = malloc( ResultSize + 1 );
52
53 if( !CharResult ) {
54 printf( "Could not alloc %d chars\n", (int)(ResultSize + 1) );
55 return 7;
56 }
57
58 RegQueryValueExA( RegKey, argv[2], NULL, NULL, (PBYTE)CharResult, &ResultSize );
59
60 printf( " char Value: %s\n", CharResult );
61 fflush( stdout );
62
63 free( WcharResult );
64 free( CharResult );
65
66 return 0;
67 }