user32: Avoid TRUE:FALSE conditional expressions.
[wine.git] / dlls / krnl386.exe16 / registry.c
blobf64e490da2696178f29676fa8cb2e935cb7bc401
1 /*
2 * 16-bit registry functions
4 * Copyright 1996 Marcus Meissner
5 * Copyright 1998 Matthew Becker
6 * Copyright 1999 Sylvain St-Germain
7 * Copyright 2002 Alexandre Julliard
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.
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.
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
24 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "wine/debug.h"
30 #include "wine/winbase16.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(reg);
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);
47 static HMODULE advapi32;
50 /* 0 and 1 are valid rootkeys in win16 shell.dll and are used by
51 * some programs. Do not remove those cases. -MM
53 static inline void fix_win16_hkey( HKEY *hkey )
55 if (*hkey == 0 || *hkey == (HKEY)1) *hkey = HKEY_CLASSES_ROOT;
58 static void init_func_ptrs(void)
60 advapi32 = LoadLibraryA("advapi32.dll");
61 if (!advapi32)
63 ERR( "Unable to load advapi32.dll\n" );
64 ExitProcess(1);
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
82 /******************************************************************************
83 * RegEnumKey [KERNEL.216]
85 DWORD WINAPI RegEnumKey16( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
87 if (!advapi32) init_func_ptrs();
88 fix_win16_hkey( &hkey );
89 return pRegEnumKeyA( hkey, index, name, name_len );
92 /******************************************************************************
93 * RegOpenKey [KERNEL.217]
95 DWORD WINAPI RegOpenKey16( HKEY hkey, LPCSTR name, PHKEY retkey )
97 if (!advapi32) init_func_ptrs();
98 fix_win16_hkey( &hkey );
99 return pRegOpenKeyA( hkey, name, retkey );
102 /******************************************************************************
103 * RegCreateKey [KERNEL.218]
105 DWORD WINAPI RegCreateKey16( HKEY hkey, LPCSTR name, PHKEY retkey )
107 if (!advapi32) init_func_ptrs();
108 fix_win16_hkey( &hkey );
109 return pRegCreateKeyA( hkey, name, retkey );
112 /******************************************************************************
113 * RegDeleteKey [KERNEL.219]
115 DWORD WINAPI RegDeleteKey16( HKEY hkey, LPCSTR name )
117 if (!advapi32) init_func_ptrs();
118 fix_win16_hkey( &hkey );
119 return pRegDeleteKeyA( hkey, name );
122 /******************************************************************************
123 * RegCloseKey [KERNEL.220]
125 DWORD WINAPI RegCloseKey16( HKEY hkey )
127 if (!advapi32) init_func_ptrs();
128 fix_win16_hkey( &hkey );
129 return pRegCloseKey( hkey );
132 /******************************************************************************
133 * RegSetValue [KERNEL.221]
135 DWORD WINAPI RegSetValue16( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
137 if (!advapi32) init_func_ptrs();
138 fix_win16_hkey( &hkey );
139 return pRegSetValueA( hkey, name, type, data, count );
142 /******************************************************************************
143 * RegDeleteValue [KERNEL.222]
145 DWORD WINAPI RegDeleteValue16( HKEY hkey, LPSTR name )
147 if (!advapi32) init_func_ptrs();
148 fix_win16_hkey( &hkey );
149 return pRegDeleteValueA( hkey, name );
152 /******************************************************************************
153 * RegEnumValue [KERNEL.223]
155 DWORD WINAPI RegEnumValue16( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
156 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
158 if (!advapi32) init_func_ptrs();
159 fix_win16_hkey( &hkey );
160 return pRegEnumValueA( hkey, index, value, val_count, reserved, type, data, count );
163 /******************************************************************************
164 * RegQueryValue [KERNEL.224]
166 * NOTES
167 * Is this HACK still applicable?
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)
174 DWORD WINAPI RegQueryValue16( HKEY hkey, LPCSTR name, LPSTR data, LPDWORD count )
176 if (!advapi32) init_func_ptrs();
177 fix_win16_hkey( &hkey );
178 if (count) *count &= 0xffff;
179 return pRegQueryValueA( hkey, name, data, (LONG*) count );
182 /******************************************************************************
183 * RegQueryValueEx [KERNEL.225]
185 DWORD WINAPI RegQueryValueEx16( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
186 LPBYTE data, LPDWORD count )
188 if (!advapi32) init_func_ptrs();
189 fix_win16_hkey( &hkey );
190 return pRegQueryValueExA( hkey, name, reserved, type, data, count );
193 /******************************************************************************
194 * RegSetValueEx [KERNEL.226]
196 DWORD WINAPI RegSetValueEx16( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
197 CONST BYTE *data, DWORD count )
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 );
205 /******************************************************************************
206 * RegFlushKey [KERNEL.227]
208 DWORD WINAPI RegFlushKey16( HKEY hkey )
210 if (!advapi32) init_func_ptrs();
211 fix_win16_hkey( &hkey );
212 return pRegFlushKey( hkey );