1 /* w32reg.c - MS-Windows Registry access
2 * Copyright (C) 1999 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 #ifdef __MINGW32__ /* This module is only used in this environment */
34 * Return a string from the Win32 Registry or NULL in case of
35 * error. Caller must release the return value. A NUKK for root
36 * is an alias fro HKEY_CURRENT_USER
37 * NOTE: The value is allocated with a plain malloc() - use free() and not
38 * the usual gcry_free()!!!
41 read_w32_registry_string( const char *root
, const char *dir
, const char *name
)
43 HKEY root_key
, key_handle
;
48 root_key
= HKEY_CURRENT_USER
;
49 else if( !strcmp( root
, "HKEY_CLASSES_ROOT" ) )
50 root_key
= HKEY_CLASSES_ROOT
;
51 else if( !strcmp( root
, "HKEY_CURRENT_USER" ) )
52 root_key
= HKEY_CURRENT_USER
;
53 else if( !strcmp( root
, "HKEY_LOCAL_MACHINE" ) )
54 root_key
= HKEY_LOCAL_MACHINE
;
55 else if( !strcmp( root
, "HKEY_USERS" ) )
56 root_key
= HKEY_USERS
;
57 else if( !strcmp( root
, "HKEY_PERFORMANCE_DATA" ) )
58 root_key
= HKEY_PERFORMANCE_DATA
;
59 else if( !strcmp( root
, "HKEY_CURRENT_CONFIG" ) )
60 root_key
= HKEY_CURRENT_CONFIG
;
64 if( RegOpenKeyEx( root_key
, dir
, 0, KEY_READ
, &key_handle
) )
65 return NULL
; /* no need for a RegClose, so return direct */
68 if( RegQueryValueEx( key_handle
, name
, 0, NULL
, NULL
, &nbytes
) )
70 result
= malloc( (n1
=nbytes
+1) );
73 if( RegQueryValueEx( key_handle
, name
, 0, NULL
, result
, &n1
) ) {
74 free(result
); result
= NULL
;
77 result
[nbytes
] = 0; /* make sure it is really a string */
80 RegCloseKey( key_handle
);
88 #endif /* __MINGW32__ */