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