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