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