1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
* 16-bit registry functions
*
* Copyright 1996 Marcus Meissner
* Copyright 1998 Matthew Becker
* Copyright 1999 Sylvain St-Germain
* Copyright 2002 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "wine/debug.h"
#include "wine/winbase16.h"
WINE_DEFAULT_DEBUG_CHANNEL(reg);
static DWORD (WINAPI *pRegCloseKey)(HKEY);
static DWORD (WINAPI *pRegCreateKeyA)(HKEY,LPCSTR,PHKEY);
static DWORD (WINAPI *pRegDeleteKeyA)(HKEY,LPCSTR);
static DWORD (WINAPI *pRegDeleteValueA)(HKEY,LPCSTR);
static DWORD (WINAPI *pRegEnumKeyA)(HKEY,DWORD,LPSTR,DWORD);
static DWORD (WINAPI *pRegEnumValueA)(HKEY,DWORD,LPSTR,LPDWORD,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
static DWORD (WINAPI *pRegFlushKey)(HKEY);
static DWORD (WINAPI *pRegOpenKeyA)(HKEY,LPCSTR,PHKEY);
static DWORD (WINAPI *pRegQueryValueA)(HKEY,LPCSTR,LPSTR,LPLONG);
static DWORD (WINAPI *pRegQueryValueExA)(HKEY,LPCSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
static DWORD (WINAPI *pRegSetValueA)(HKEY,LPCSTR,DWORD,LPCSTR,DWORD);
static DWORD (WINAPI *pRegSetValueExA)(HKEY,LPCSTR,DWORD,DWORD,CONST BYTE*,DWORD);
static HMODULE advapi32;
/* 0 and 1 are valid rootkeys in win16 shell.dll and are used by
* some programs. Do not remove those cases. -MM
*/
static inline void fix_win16_hkey( HKEY *hkey )
{
if (*hkey == 0 || *hkey == (HKEY)1) *hkey = HKEY_CLASSES_ROOT;
}
static void init_func_ptrs(void)
{
advapi32 = LoadLibraryA("advapi32.dll");
if (!advapi32)
{
ERR( "Unable to load advapi32.dll\n" );
ExitProcess(1);
}
#define GET_PTR(name) p##name = (void *)GetProcAddress(advapi32,#name);
GET_PTR( RegCloseKey );
GET_PTR( RegCreateKeyA );
GET_PTR( RegDeleteKeyA );
GET_PTR( RegDeleteValueA );
GET_PTR( RegEnumKeyA );
GET_PTR( RegEnumValueA );
GET_PTR( RegFlushKey );
GET_PTR( RegOpenKeyA );
GET_PTR( RegQueryValueA );
GET_PTR( RegQueryValueExA );
GET_PTR( RegSetValueA );
GET_PTR( RegSetValueExA );
#undef GET_PTR
}
/******************************************************************************
* RegEnumKey [KERNEL.216]
*/
DWORD WINAPI RegEnumKey16( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegEnumKeyA( hkey, index, name, name_len );
}
/******************************************************************************
* RegOpenKey [KERNEL.217]
*/
DWORD WINAPI RegOpenKey16( HKEY hkey, LPCSTR name, PHKEY retkey )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegOpenKeyA( hkey, name, retkey );
}
/******************************************************************************
* RegCreateKey [KERNEL.218]
*/
DWORD WINAPI RegCreateKey16( HKEY hkey, LPCSTR name, PHKEY retkey )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegCreateKeyA( hkey, name, retkey );
}
/******************************************************************************
* RegDeleteKey [KERNEL.219]
*/
DWORD WINAPI RegDeleteKey16( HKEY hkey, LPCSTR name )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegDeleteKeyA( hkey, name );
}
/******************************************************************************
* RegCloseKey [KERNEL.220]
*/
DWORD WINAPI RegCloseKey16( HKEY hkey )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegCloseKey( hkey );
}
/******************************************************************************
* RegSetValue [KERNEL.221]
*/
DWORD WINAPI RegSetValue16( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegSetValueA( hkey, name, type, data, count );
}
/******************************************************************************
* RegDeleteValue [KERNEL.222]
*/
DWORD WINAPI RegDeleteValue16( HKEY hkey, LPSTR name )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegDeleteValueA( hkey, name );
}
/******************************************************************************
* RegEnumValue [KERNEL.223]
*/
DWORD WINAPI RegEnumValue16( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegEnumValueA( hkey, index, value, val_count, reserved, type, data, count );
}
/******************************************************************************
* RegQueryValue [KERNEL.224]
*
* NOTES
* Is this HACK still applicable?
*
* HACK
* The 16bit RegQueryValue doesn't handle selectorblocks anyway, so we just
* mask out the high 16 bit. This (not so much incidently) hopefully fixes
* Aldus FH4)
*/
DWORD WINAPI RegQueryValue16( HKEY hkey, LPCSTR name, LPSTR data, LPDWORD count )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
if (count) *count &= 0xffff;
return pRegQueryValueA( hkey, name, data, (LONG*) count );
}
/******************************************************************************
* RegQueryValueEx [KERNEL.225]
*/
DWORD WINAPI RegQueryValueEx16( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
LPBYTE data, LPDWORD count )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegQueryValueExA( hkey, name, reserved, type, data, count );
}
/******************************************************************************
* RegSetValueEx [KERNEL.226]
*/
DWORD WINAPI RegSetValueEx16( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
CONST BYTE *data, DWORD count )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
if (!count && (type==REG_SZ)) count = strlen( (const char *)data );
return pRegSetValueExA( hkey, name, reserved, type, data, count );
}
/******************************************************************************
* RegFlushKey [KERNEL.227]
*/
DWORD WINAPI RegFlushKey16( HKEY hkey )
{
if (!advapi32) init_func_ptrs();
fix_win16_hkey( &hkey );
return pRegFlushKey( hkey );
}