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
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(reg
);
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
);
46 static HMODULE advapi32
;
49 /* 0 and 1 are valid rootkeys in win16 shell.dll and are used by
50 * some programs. Do not remove those cases. -MM
52 static inline void fix_win16_hkey( HKEY
*hkey
)
54 if (*hkey
== 0 || *hkey
== (HKEY
)1) *hkey
= HKEY_CLASSES_ROOT
;
57 static void init_func_ptrs(void)
59 advapi32
= LoadLibraryA("advapi32.dll");
62 ERR( "Unable to load advapi32.dll\n" );
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
);
81 /******************************************************************************
82 * RegEnumKey [KERNEL.216]
84 DWORD WINAPI
RegEnumKey16( HKEY hkey
, DWORD index
, LPSTR name
, DWORD name_len
)
86 if (!advapi32
) init_func_ptrs();
87 fix_win16_hkey( &hkey
);
88 return pRegEnumKeyA( hkey
, index
, name
, name_len
);
91 /******************************************************************************
92 * RegOpenKey [KERNEL.217]
94 DWORD WINAPI
RegOpenKey16( HKEY hkey
, LPCSTR name
, PHKEY retkey
)
96 if (!advapi32
) init_func_ptrs();
97 fix_win16_hkey( &hkey
);
98 return pRegOpenKeyA( hkey
, name
, retkey
);
101 /******************************************************************************
102 * RegCreateKey [KERNEL.218]
104 DWORD WINAPI
RegCreateKey16( HKEY hkey
, LPCSTR name
, PHKEY retkey
)
106 if (!advapi32
) init_func_ptrs();
107 fix_win16_hkey( &hkey
);
108 return pRegCreateKeyA( hkey
, name
, retkey
);
111 /******************************************************************************
112 * RegDeleteKey [KERNEL.219]
114 DWORD WINAPI
RegDeleteKey16( HKEY hkey
, LPCSTR name
)
116 if (!advapi32
) init_func_ptrs();
117 fix_win16_hkey( &hkey
);
118 return pRegDeleteKeyA( hkey
, name
);
121 /******************************************************************************
122 * RegCloseKey [KERNEL.220]
124 DWORD WINAPI
RegCloseKey16( HKEY hkey
)
126 if (!advapi32
) init_func_ptrs();
127 fix_win16_hkey( &hkey
);
128 return pRegCloseKey( hkey
);
131 /******************************************************************************
132 * RegSetValue [KERNEL.221]
134 DWORD WINAPI
RegSetValue16( HKEY hkey
, LPCSTR name
, DWORD type
, LPCSTR data
, DWORD count
)
136 if (!advapi32
) init_func_ptrs();
137 fix_win16_hkey( &hkey
);
138 return pRegSetValueA( hkey
, name
, type
, data
, count
);
141 /******************************************************************************
142 * RegDeleteValue [KERNEL.222]
144 DWORD WINAPI
RegDeleteValue16( HKEY hkey
, LPSTR name
)
146 if (!advapi32
) init_func_ptrs();
147 fix_win16_hkey( &hkey
);
148 return pRegDeleteValueA( hkey
, name
);
151 /******************************************************************************
152 * RegEnumValue [KERNEL.223]
154 DWORD WINAPI
RegEnumValue16( HKEY hkey
, DWORD index
, LPSTR value
, LPDWORD val_count
,
155 LPDWORD reserved
, LPDWORD type
, LPBYTE data
, LPDWORD count
)
157 if (!advapi32
) init_func_ptrs();
158 fix_win16_hkey( &hkey
);
159 return pRegEnumValueA( hkey
, index
, value
, val_count
, reserved
, type
, data
, count
);
162 /******************************************************************************
163 * RegQueryValue [KERNEL.224]
166 * Is this HACK still applicable?
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
173 DWORD WINAPI
RegQueryValue16( HKEY hkey
, LPCSTR name
, LPSTR data
, LPDWORD count
)
175 if (!advapi32
) init_func_ptrs();
176 fix_win16_hkey( &hkey
);
177 if (count
) *count
&= 0xffff;
178 return pRegQueryValueA( hkey
, name
, data
, count
);
181 /******************************************************************************
182 * RegQueryValueEx [KERNEL.225]
184 DWORD WINAPI
RegQueryValueEx16( HKEY hkey
, LPCSTR name
, LPDWORD reserved
, LPDWORD type
,
185 LPBYTE data
, LPDWORD count
)
187 if (!advapi32
) init_func_ptrs();
188 fix_win16_hkey( &hkey
);
189 return pRegQueryValueExA( hkey
, name
, reserved
, type
, data
, count
);
192 /******************************************************************************
193 * RegSetValueEx [KERNEL.226]
195 DWORD WINAPI
RegSetValueEx16( HKEY hkey
, LPCSTR name
, DWORD reserved
, DWORD type
,
196 CONST BYTE
*data
, DWORD count
)
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
);
204 /******************************************************************************
205 * RegFlushKey [KERNEL.227]
207 DWORD WINAPI
RegFlushKey16( HKEY hkey
)
209 if (!advapi32
) init_func_ptrs();
210 fix_win16_hkey( &hkey
);
211 return pRegFlushKey( hkey
);