Always open the device in the default 22050x8x2 format, and let it
[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 "winbase.h"
25 #include "winreg.h"
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(reg);
29
30 DWORD (WINAPI *pRegCloseKey)(HKEY);
31 DWORD (WINAPI *pRegCreateKeyA)(HKEY,LPCSTR,PHKEY);
32 DWORD (WINAPI *pRegDeleteKeyA)(HKEY,LPCSTR);
33 DWORD (WINAPI *pRegDeleteValueA)(HKEY,LPCSTR);
34 DWORD (WINAPI *pRegEnumKeyA)(HKEY,DWORD,LPSTR,DWORD);
35 DWORD (WINAPI *pRegEnumValueA)(HKEY,DWORD,LPSTR,LPDWORD,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
36 DWORD (WINAPI *pRegFlushKey)(HKEY);
37 DWORD (WINAPI *pRegOpenKeyA)(HKEY,LPCSTR,PHKEY);
38 DWORD (WINAPI *pRegQueryValueA)(HKEY,LPCSTR,LPSTR,LPLONG);
39 DWORD (WINAPI *pRegQueryValueExA)(HKEY,LPCSTR,LPDWORD,LPDWORD,LPBYTE,LPDWORD);
40 DWORD (WINAPI *pRegSetValueA)(HKEY,LPCSTR,DWORD,LPCSTR,DWORD);
41 DWORD (WINAPI *pRegSetValueExA)(HKEY,LPCSTR,DWORD,DWORD,CONST BYTE*,DWORD);
42
43 static HMODULE advapi32;
44
45
46 /* 0 and 1 are valid rootkeys in win16 shell.dll and are used by
47  * some programs. Do not remove those cases. -MM
48  */
49 static inline void fix_win16_hkey( HKEY *hkey )
50 {
51     if (*hkey == 0 || *hkey == (HKEY)1) *hkey = HKEY_CLASSES_ROOT;
52 }
53
54 static void init_func_ptrs(void)
55 {
56     advapi32 = LoadLibraryA("advapi32.dll");
57     if (!advapi32)
58     {
59         ERR( "Unable to load advapi32.dll\n" );
60         ExitProcess(1);
61     }
62 #define GET_PTR(name)  p##name = (void *)GetProcAddress(advapi32,#name);
63     GET_PTR( RegCloseKey );
64     GET_PTR( RegCreateKeyA );
65     GET_PTR( RegDeleteKeyA );
66     GET_PTR( RegDeleteValueA );
67     GET_PTR( RegEnumKeyA );
68     GET_PTR( RegEnumValueA );
69     GET_PTR( RegFlushKey );
70     GET_PTR( RegOpenKeyA );
71     GET_PTR( RegQueryValueA );
72     GET_PTR( RegQueryValueExA );
73     GET_PTR( RegSetValueA );
74     GET_PTR( RegSetValueExA );
75 #undef GET_PTR
76 }
77
78 /******************************************************************************
79  *           RegEnumKey   [KERNEL.216]
80  */
81 DWORD WINAPI RegEnumKey16( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
82 {
83     if (!advapi32) init_func_ptrs();
84     fix_win16_hkey( &hkey );
85     return pRegEnumKeyA( hkey, index, name, name_len );
86 }
87
88 /******************************************************************************
89  *           RegOpenKey   [KERNEL.217]
90  */
91 DWORD WINAPI RegOpenKey16( HKEY hkey, LPCSTR name, PHKEY retkey )
92 {
93     if (!advapi32) init_func_ptrs();
94     fix_win16_hkey( &hkey );
95     return pRegOpenKeyA( hkey, name, retkey );
96 }
97
98 /******************************************************************************
99  *           RegCreateKey   [KERNEL.218]
100  */
101 DWORD WINAPI RegCreateKey16( HKEY hkey, LPCSTR name, PHKEY retkey )
102 {
103     if (!advapi32) init_func_ptrs();
104     fix_win16_hkey( &hkey );
105     return pRegCreateKeyA( hkey, name, retkey );
106 }
107
108 /******************************************************************************
109  *           RegDeleteKey   [KERNEL.219]
110  */
111 DWORD WINAPI RegDeleteKey16( HKEY hkey, LPCSTR name )
112 {
113     if (!advapi32) init_func_ptrs();
114     fix_win16_hkey( &hkey );
115     return pRegDeleteKeyA( hkey, name );
116 }
117
118 /******************************************************************************
119  *           RegCloseKey   [KERNEL.220]
120  */
121 DWORD WINAPI RegCloseKey16( HKEY hkey )
122 {
123     if (!advapi32) init_func_ptrs();
124     fix_win16_hkey( &hkey );
125     return pRegCloseKey( hkey );
126 }
127
128 /******************************************************************************
129  *           RegSetValue   [KERNEL.221]
130  */
131 DWORD WINAPI RegSetValue16( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
132 {
133     if (!advapi32) init_func_ptrs();
134     fix_win16_hkey( &hkey );
135     return pRegSetValueA( hkey, name, type, data, count );
136 }
137
138 /******************************************************************************
139  *           RegDeleteValue  [KERNEL.222]
140  */
141 DWORD WINAPI RegDeleteValue16( HKEY hkey, LPSTR name )
142 {
143     if (!advapi32) init_func_ptrs();
144     fix_win16_hkey( &hkey );
145     return pRegDeleteValueA( hkey, name );
146 }
147
148 /******************************************************************************
149  *           RegEnumValue   [KERNEL.223]
150  */
151 DWORD WINAPI RegEnumValue16( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
152                              LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
153 {
154     if (!advapi32) init_func_ptrs();
155     fix_win16_hkey( &hkey );
156     return pRegEnumValueA( hkey, index, value, val_count, reserved, type, data, count );
157 }
158
159 /******************************************************************************
160  *           RegQueryValue   [KERNEL.224]
161  *
162  * NOTES
163  *    Is this HACK still applicable?
164  *
165  * HACK
166  *    The 16bit RegQueryValue doesn't handle selectorblocks anyway, so we just
167  *    mask out the high 16 bit.  This (not so much incidently) hopefully fixes
168  *    Aldus FH4)
169  */
170 DWORD WINAPI RegQueryValue16( HKEY hkey, LPCSTR name, LPSTR data, LPDWORD count )
171 {
172     if (!advapi32) init_func_ptrs();
173     fix_win16_hkey( &hkey );
174     if (count) *count &= 0xffff;
175     return pRegQueryValueA( hkey, name, data, count );
176 }
177
178 /******************************************************************************
179  *           RegQueryValueEx   [KERNEL.225]
180  */
181 DWORD WINAPI RegQueryValueEx16( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
182                                 LPBYTE data, LPDWORD count )
183 {
184     if (!advapi32) init_func_ptrs();
185     fix_win16_hkey( &hkey );
186     return pRegQueryValueExA( hkey, name, reserved, type, data, count );
187 }
188
189 /******************************************************************************
190  *           RegSetValueEx   [KERNEL.226]
191  */
192 DWORD WINAPI RegSetValueEx16( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
193                               CONST BYTE *data, DWORD count )
194 {
195     if (!advapi32) init_func_ptrs();
196     fix_win16_hkey( &hkey );
197     if (!count && (type==REG_SZ)) count = strlen(data);
198     return pRegSetValueExA( hkey, name, reserved, type, data, count );
199 }
200
201 /******************************************************************************
202  *           RegFlushKey   [KERNEL.227]
203  */
204 DWORD WINAPI RegFlushKey16( HKEY hkey )
205 {
206     if (!advapi32) init_func_ptrs();
207     fix_win16_hkey( &hkey );
208     return pRegFlushKey( hkey );
209 }