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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(reg);
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);
43 static HMODULE advapi32;
46 /* 0 and 1 are valid rootkeys in win16 shell.dll and are used by
47 * some programs. Do not remove those cases. -MM
49 static inline void fix_win16_hkey( HKEY *hkey )
51 if (*hkey == 0 || *hkey == (HKEY)1) *hkey = HKEY_CLASSES_ROOT;
54 static void init_func_ptrs(void)
56 advapi32 = LoadLibraryA("advapi32.dll");
59 ERR( "Unable to load advapi32.dll\n" );
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 );
78 /******************************************************************************
79 * RegEnumKey [KERNEL.216]
81 DWORD WINAPI RegEnumKey16( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
83 if (!advapi32) init_func_ptrs();
84 fix_win16_hkey( &hkey );
85 return pRegEnumKeyA( hkey, index, name, name_len );
88 /******************************************************************************
89 * RegOpenKey [KERNEL.217]
91 DWORD WINAPI RegOpenKey16( HKEY hkey, LPCSTR name, PHKEY retkey )
93 if (!advapi32) init_func_ptrs();
94 fix_win16_hkey( &hkey );
95 return pRegOpenKeyA( hkey, name, retkey );
98 /******************************************************************************
99 * RegCreateKey [KERNEL.218]
101 DWORD WINAPI RegCreateKey16( HKEY hkey, LPCSTR name, PHKEY retkey )
103 if (!advapi32) init_func_ptrs();
104 fix_win16_hkey( &hkey );
105 return pRegCreateKeyA( hkey, name, retkey );
108 /******************************************************************************
109 * RegDeleteKey [KERNEL.219]
111 DWORD WINAPI RegDeleteKey16( HKEY hkey, LPCSTR name )
113 if (!advapi32) init_func_ptrs();
114 fix_win16_hkey( &hkey );
115 return pRegDeleteKeyA( hkey, name );
118 /******************************************************************************
119 * RegCloseKey [KERNEL.220]
121 DWORD WINAPI RegCloseKey16( HKEY hkey )
123 if (!advapi32) init_func_ptrs();
124 fix_win16_hkey( &hkey );
125 return pRegCloseKey( hkey );
128 /******************************************************************************
129 * RegSetValue [KERNEL.221]
131 DWORD WINAPI RegSetValue16( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
133 if (!advapi32) init_func_ptrs();
134 fix_win16_hkey( &hkey );
135 return pRegSetValueA( hkey, name, type, data, count );
138 /******************************************************************************
139 * RegDeleteValue [KERNEL.222]
141 DWORD WINAPI RegDeleteValue16( HKEY hkey, LPSTR name )
143 if (!advapi32) init_func_ptrs();
144 fix_win16_hkey( &hkey );
145 return pRegDeleteValueA( hkey, name );
148 /******************************************************************************
149 * RegEnumValue [KERNEL.223]
151 DWORD WINAPI RegEnumValue16( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
152 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
154 if (!advapi32) init_func_ptrs();
155 fix_win16_hkey( &hkey );
156 return pRegEnumValueA( hkey, index, value, val_count, reserved, type, data, count );
159 /******************************************************************************
160 * RegQueryValue [KERNEL.224]
163 * Is this HACK still applicable?
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
170 DWORD WINAPI RegQueryValue16( HKEY hkey, LPCSTR name, LPSTR data, LPDWORD count )
172 if (!advapi32) init_func_ptrs();
173 fix_win16_hkey( &hkey );
174 if (count) *count &= 0xffff;
175 return pRegQueryValueA( hkey, name, data, count );
178 /******************************************************************************
179 * RegQueryValueEx [KERNEL.225]
181 DWORD WINAPI RegQueryValueEx16( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
182 LPBYTE data, LPDWORD count )
184 if (!advapi32) init_func_ptrs();
185 fix_win16_hkey( &hkey );
186 return pRegQueryValueExA( hkey, name, reserved, type, data, count );
189 /******************************************************************************
190 * RegSetValueEx [KERNEL.226]
192 DWORD WINAPI RegSetValueEx16( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
193 CONST BYTE *data, DWORD count )
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 );
201 /******************************************************************************
202 * RegFlushKey [KERNEL.227]
204 DWORD WINAPI RegFlushKey16( HKEY hkey )
206 if (!advapi32) init_func_ptrs();
207 fix_win16_hkey( &hkey );
208 return pRegFlushKey( hkey );