4 * Copyright (C) 1999 Alexandre Julliard
6 * Based on misc/registry.c code
7 * Copyright (C) 1996 Marcus Meissner
8 * Copyright (C) 1998 Matthew Becker
9 * Copyright (C) 1999 Sylvain St-Germain
11 * This file is concerned about handle management and interaction with the Wine server.
12 * Registry file I/O is in misc/registry.c.
14 * This library is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include "wine/unicode.h"
38 #include "wine/server.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(reg);
44 /* check if value type needs string conversion (Ansi<->Unicode) */
45 inline static int is_string( DWORD type )
47 return (type == REG_SZ) || (type == REG_EXPAND_SZ) || (type == REG_MULTI_SZ);
50 /* check if current version is NT or Win95 */
51 inline static int is_version_nt(void)
53 return !(GetVersion() & 0x80000000);
56 /* allowed bits for access mask */
57 #define KEY_ACCESS_MASK (KEY_ALL_ACCESS | MAXIMUM_ALLOWED)
59 /******************************************************************************
60 * RegCreateKeyExW [ADVAPI32.@]
63 * hkey [I] Handle of an open key
64 * name [I] Address of subkey name
65 * reserved [I] Reserved - must be 0
66 * class [I] Address of class string
67 * options [I] Special options flag
68 * access [I] Desired security access
69 * sa [I] Address of key security structure
70 * retkey [O] Address of buffer for opened handle
71 * dispos [O] Receives REG_CREATED_NEW_KEY or REG_OPENED_EXISTING_KEY
74 * in case of failing retkey remains untouched
76 * FIXME MAXIMUM_ALLOWED in access mask not supported by server
78 DWORD WINAPI RegCreateKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, LPWSTR class,
79 DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa,
80 LPHKEY retkey, LPDWORD dispos )
82 OBJECT_ATTRIBUTES attr;
83 UNICODE_STRING nameW, classW;
85 if (reserved) return ERROR_INVALID_PARAMETER;
86 if (!(access & KEY_ACCESS_MASK) || (access & ~KEY_ACCESS_MASK)) return ERROR_ACCESS_DENIED;
88 attr.Length = sizeof(attr);
89 attr.RootDirectory = hkey;
90 attr.ObjectName = &nameW;
92 attr.SecurityDescriptor = NULL;
93 attr.SecurityQualityOfService = NULL;
94 RtlInitUnicodeString( &nameW, name );
95 RtlInitUnicodeString( &classW, class );
97 return RtlNtStatusToDosError( NtCreateKey( retkey, access, &attr, 0,
98 &classW, options, dispos ) );
102 /******************************************************************************
103 * RegCreateKeyExA [ADVAPI32.@]
105 * FIXME MAXIMUM_ALLOWED in access mask not supported by server
107 DWORD WINAPI RegCreateKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, LPSTR class,
108 DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa,
109 LPHKEY retkey, LPDWORD dispos )
111 OBJECT_ATTRIBUTES attr;
112 UNICODE_STRING classW;
113 ANSI_STRING nameA, classA;
116 if (reserved) return ERROR_INVALID_PARAMETER;
117 if (!is_version_nt()) access = KEY_ALL_ACCESS; /* Win95 ignores the access mask */
118 else if (!(access & KEY_ACCESS_MASK) || (access & ~KEY_ACCESS_MASK)) return ERROR_ACCESS_DENIED;
120 attr.Length = sizeof(attr);
121 attr.RootDirectory = hkey;
122 attr.ObjectName = &NtCurrentTeb()->StaticUnicodeString;
124 attr.SecurityDescriptor = NULL;
125 attr.SecurityQualityOfService = NULL;
126 RtlInitAnsiString( &nameA, name );
127 RtlInitAnsiString( &classA, class );
129 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
132 if (!(status = RtlAnsiStringToUnicodeString( &classW, &classA, TRUE )))
134 status = NtCreateKey( retkey, access, &attr, 0, &classW, options, dispos );
135 RtlFreeUnicodeString( &classW );
138 return RtlNtStatusToDosError( status );
142 /******************************************************************************
143 * RegCreateKeyW [ADVAPI32.@]
145 DWORD WINAPI RegCreateKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
147 /* FIXME: previous implementation converted ERROR_INVALID_HANDLE to ERROR_BADKEY, */
148 /* but at least my version of NT (4.0 SP5) doesn't do this. -- AJ */
149 return RegCreateKeyExW( hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
150 KEY_ALL_ACCESS, NULL, retkey, NULL );
154 /******************************************************************************
155 * RegCreateKeyA [ADVAPI32.@]
157 DWORD WINAPI RegCreateKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
159 return RegCreateKeyExA( hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
160 KEY_ALL_ACCESS, NULL, retkey, NULL );
165 /******************************************************************************
166 * RegOpenKeyExW [ADVAPI32.@]
168 * Opens the specified key
170 * Unlike RegCreateKeyEx, this does not create the key if it does not exist.
173 * hkey [I] Handle of open key
174 * name [I] Name of subkey to open
175 * reserved [I] Reserved - must be zero
176 * access [I] Security access mask
177 * retkey [O] Handle to open key
180 * Success: ERROR_SUCCESS
181 * Failure: Error code
184 * in case of failing is retkey = 0
186 DWORD WINAPI RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, REGSAM access, LPHKEY retkey )
188 OBJECT_ATTRIBUTES attr;
189 UNICODE_STRING nameW;
191 attr.Length = sizeof(attr);
192 attr.RootDirectory = hkey;
193 attr.ObjectName = &nameW;
195 attr.SecurityDescriptor = NULL;
196 attr.SecurityQualityOfService = NULL;
197 RtlInitUnicodeString( &nameW, name );
198 return RtlNtStatusToDosError( NtOpenKey( retkey, access, &attr ) );
202 /******************************************************************************
203 * RegOpenKeyExA [ADVAPI32.@]
205 DWORD WINAPI RegOpenKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, REGSAM access, LPHKEY retkey )
207 OBJECT_ATTRIBUTES attr;
211 if (!is_version_nt()) access = KEY_ALL_ACCESS; /* Win95 ignores the access mask */
213 attr.Length = sizeof(attr);
214 attr.RootDirectory = hkey;
215 attr.ObjectName = &NtCurrentTeb()->StaticUnicodeString;
217 attr.SecurityDescriptor = NULL;
218 attr.SecurityQualityOfService = NULL;
220 RtlInitAnsiString( &nameA, name );
221 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
224 status = NtOpenKey( retkey, access, &attr );
226 return RtlNtStatusToDosError( status );
230 /******************************************************************************
231 * RegOpenKeyW [ADVAPI32.@]
234 * hkey [I] Handle of open key
235 * name [I] Address of name of subkey to open
236 * retkey [O] Handle to open key
239 * Success: ERROR_SUCCESS
240 * Failure: Error code
243 * in case of failing is retkey = 0
245 DWORD WINAPI RegOpenKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
247 return RegOpenKeyExW( hkey, name, 0, KEY_ALL_ACCESS, retkey );
251 /******************************************************************************
252 * RegOpenKeyA [ADVAPI32.@]
254 DWORD WINAPI RegOpenKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
256 return RegOpenKeyExA( hkey, name, 0, KEY_ALL_ACCESS, retkey );
260 /******************************************************************************
261 * RegOpenCurrentUser [ADVAPI32.@]
262 * FIXME: This function is supposed to retrieve a handle to the
263 * HKEY_CURRENT_USER for the user the current thread is impersonating.
264 * Since Wine does not currently allow threads to impersonate other users,
265 * this stub should work fine.
267 DWORD WINAPI RegOpenCurrentUser( REGSAM access, PHKEY retkey )
269 return RegOpenKeyExA( HKEY_CURRENT_USER, "", 0, access, retkey );
274 /******************************************************************************
275 * RegEnumKeyExW [ADVAPI32.@]
278 * hkey [I] Handle to key to enumerate
279 * index [I] Index of subkey to enumerate
280 * name [O] Buffer for subkey name
281 * name_len [O] Size of subkey buffer
282 * reserved [I] Reserved
283 * class [O] Buffer for class string
284 * class_len [O] Size of class buffer
285 * ft [O] Time key last written to
287 DWORD WINAPI RegEnumKeyExW( HKEY hkey, DWORD index, LPWSTR name, LPDWORD name_len,
288 LPDWORD reserved, LPWSTR class, LPDWORD class_len, FILETIME *ft )
291 char buffer[256], *buf_ptr = buffer;
292 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
295 TRACE( "(0x%x,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey, index, name, name_len,
296 name_len ? *name_len : -1, reserved, class, class_len, ft );
298 if (reserved) return ERROR_INVALID_PARAMETER;
300 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
301 buffer, sizeof(buffer), &total_size );
303 while (status == STATUS_BUFFER_OVERFLOW)
305 /* retry with a dynamically allocated buffer */
306 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
307 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
308 return ERROR_NOT_ENOUGH_MEMORY;
309 info = (KEY_NODE_INFORMATION *)buf_ptr;
310 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
311 buf_ptr, total_size, &total_size );
316 DWORD len = info->NameLength / sizeof(WCHAR);
317 DWORD cls_len = info->ClassLength / sizeof(WCHAR);
319 if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
321 if (len >= *name_len || (class && class_len && (cls_len >= *class_len)))
322 status = STATUS_BUFFER_OVERFLOW;
326 memcpy( name, info->Name, info->NameLength );
330 *class_len = cls_len;
333 memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
340 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
341 return RtlNtStatusToDosError( status );
345 /******************************************************************************
346 * RegEnumKeyExA [ADVAPI32.@]
348 DWORD WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_len,
349 LPDWORD reserved, LPSTR class, LPDWORD class_len, FILETIME *ft )
352 char buffer[256], *buf_ptr = buffer;
353 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
356 TRACE( "(0x%x,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey, index, name, name_len,
357 name_len ? *name_len : -1, reserved, class, class_len, ft );
359 if (reserved) return ERROR_INVALID_PARAMETER;
361 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
362 buffer, sizeof(buffer), &total_size );
364 while (status == STATUS_BUFFER_OVERFLOW)
366 /* retry with a dynamically allocated buffer */
367 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
368 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
369 return ERROR_NOT_ENOUGH_MEMORY;
370 info = (KEY_NODE_INFORMATION *)buf_ptr;
371 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
372 buf_ptr, total_size, &total_size );
379 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
380 RtlUnicodeToMultiByteSize( &cls_len, (WCHAR *)(buf_ptr + info->ClassOffset),
382 if (ft) *ft = *(FILETIME *)&info->LastWriteTime;
384 if (len >= *name_len || (class && class_len && (cls_len >= *class_len)))
385 status = STATUS_BUFFER_OVERFLOW;
389 RtlUnicodeToMultiByteN( name, len, NULL, info->Name, info->NameLength );
393 *class_len = cls_len;
396 RtlUnicodeToMultiByteN( class, cls_len, NULL,
397 (WCHAR *)(buf_ptr + info->ClassOffset),
405 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
406 return RtlNtStatusToDosError( status );
410 /******************************************************************************
411 * RegEnumKeyW [ADVAPI32.@]
413 DWORD WINAPI RegEnumKeyW( HKEY hkey, DWORD index, LPWSTR name, DWORD name_len )
415 return RegEnumKeyExW( hkey, index, name, &name_len, NULL, NULL, NULL, NULL );
419 /******************************************************************************
420 * RegEnumKeyA [ADVAPI32.@]
422 DWORD WINAPI RegEnumKeyA( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
424 return RegEnumKeyExA( hkey, index, name, &name_len, NULL, NULL, NULL, NULL );
428 /******************************************************************************
429 * RegQueryInfoKeyW [ADVAPI32.@]
432 * hkey [I] Handle to key to query
433 * class [O] Buffer for class string
434 * class_len [O] Size of class string buffer
435 * reserved [I] Reserved
436 * subkeys [O] Buffer for number of subkeys
437 * max_subkey [O] Buffer for longest subkey name length
438 * max_class [O] Buffer for longest class string length
439 * values [O] Buffer for number of value entries
440 * max_value [O] Buffer for longest value name length
441 * max_data [O] Buffer for longest value data length
442 * security [O] Buffer for security descriptor length
443 * modif [O] Modification time
445 * - win95 allows class to be valid and class_len to be NULL
446 * - winnt returns ERROR_INVALID_PARAMETER if class is valid and class_len is NULL
447 * - both allow class to be NULL and class_len to be NULL
448 * (it's hard to test validity, so test !NULL instead)
450 DWORD WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPDWORD reserved,
451 LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
452 LPDWORD values, LPDWORD max_value, LPDWORD max_data,
453 LPDWORD security, FILETIME *modif )
456 char buffer[256], *buf_ptr = buffer;
457 KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
460 TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
461 reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
463 if (class && !class_len && is_version_nt()) return ERROR_INVALID_PARAMETER;
465 status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
466 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
470 /* retry with a dynamically allocated buffer */
471 while (status == STATUS_BUFFER_OVERFLOW)
473 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
474 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
475 return ERROR_NOT_ENOUGH_MEMORY;
476 info = (KEY_FULL_INFORMATION *)buf_ptr;
477 status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
480 if (status) goto done;
482 if (class_len && (info->ClassLength/sizeof(WCHAR) + 1 > *class_len))
484 status = STATUS_BUFFER_OVERFLOW;
488 memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
489 class[info->ClassLength/sizeof(WCHAR)] = 0;
492 else status = STATUS_SUCCESS;
494 if (class_len) *class_len = info->ClassLength / sizeof(WCHAR);
495 if (subkeys) *subkeys = info->SubKeys;
496 if (max_subkey) *max_subkey = info->MaxNameLen;
497 if (max_class) *max_class = info->MaxClassLen;
498 if (values) *values = info->Values;
499 if (max_value) *max_value = info->MaxValueNameLen;
500 if (max_data) *max_data = info->MaxValueDataLen;
501 if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
504 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
505 return RtlNtStatusToDosError( status );
509 /******************************************************************************
510 * RegQueryInfoKeyA [ADVAPI32.@]
512 DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWORD reserved,
513 LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
514 LPDWORD values, LPDWORD max_value, LPDWORD max_data,
515 LPDWORD security, FILETIME *modif )
518 char buffer[256], *buf_ptr = buffer;
519 KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
520 DWORD total_size, len;
522 TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
523 reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
525 if (class && !class_len && is_version_nt()) return ERROR_INVALID_PARAMETER;
527 status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
528 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
530 if (class || class_len)
532 /* retry with a dynamically allocated buffer */
533 while (status == STATUS_BUFFER_OVERFLOW)
535 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
536 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
537 return ERROR_NOT_ENOUGH_MEMORY;
538 info = (KEY_FULL_INFORMATION *)buf_ptr;
539 status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
542 if (status) goto done;
544 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->ClassOffset), info->ClassLength);
547 if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW;
550 if (class && !status)
552 RtlUnicodeToMultiByteN( class, len, NULL, (WCHAR *)(buf_ptr + info->ClassOffset),
557 else status = STATUS_SUCCESS;
559 if (subkeys) *subkeys = info->SubKeys;
560 if (max_subkey) *max_subkey = info->MaxNameLen;
561 if (max_class) *max_class = info->MaxClassLen;
562 if (values) *values = info->Values;
563 if (max_value) *max_value = info->MaxValueNameLen;
564 if (max_data) *max_data = info->MaxValueDataLen;
565 if (modif) *modif = *(FILETIME *)&info->LastWriteTime;
568 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
569 return RtlNtStatusToDosError( status );
573 /******************************************************************************
574 * RegCloseKey [ADVAPI32.@]
576 * Releases the handle of the specified key
579 * hkey [I] Handle of key to close
582 * Success: ERROR_SUCCESS
583 * Failure: Error code
585 DWORD WINAPI RegCloseKey( HKEY hkey )
587 if (!hkey || hkey >= 0x80000000) return ERROR_SUCCESS;
588 return RtlNtStatusToDosError( NtClose( hkey ) );
592 /******************************************************************************
593 * RegDeleteKeyW [ADVAPI32.@]
596 * hkey [I] Handle to open key
597 * name [I] Name of subkey to delete
600 * Success: ERROR_SUCCESS
601 * Failure: Error code
603 DWORD WINAPI RegDeleteKeyW( HKEY hkey, LPCWSTR name )
610 ret = RtlNtStatusToDosError( NtDeleteKey( hkey ) );
612 else if (!(ret = RegOpenKeyExW( hkey, name, 0, 0, &tmp )))
614 if (!is_version_nt()) /* win95 does recursive key deletes */
616 WCHAR name[MAX_PATH];
618 while(!RegEnumKeyW(tmp, 0, name, sizeof name))
620 if(RegDeleteKeyW(tmp, name)) /* recurse */
624 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
627 TRACE("%s ret=%08lx\n", debugstr_w(name), ret);
632 /******************************************************************************
633 * RegDeleteKeyA [ADVAPI32.@]
635 DWORD WINAPI RegDeleteKeyA( HKEY hkey, LPCSTR name )
642 ret = RtlNtStatusToDosError( NtDeleteKey( hkey ) );
644 else if (!(ret = RegOpenKeyExA( hkey, name, 0, KEY_ALL_ACCESS, &tmp )))
646 if (!is_version_nt()) /* win95 does recursive key deletes */
650 while(!RegEnumKeyA(tmp, 0, name, sizeof name))
652 if(RegDeleteKeyA(tmp, name)) /* recurse */
656 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
659 TRACE("%s ret=%08lx\n", debugstr_a(name), ret);
665 /******************************************************************************
666 * RegSetValueExW [ADVAPI32.@]
668 * Sets the data and type of a value under a register key
671 * hkey [I] Handle of key to set value for
672 * name [I] Name of value to set
673 * reserved [I] Reserved - must be zero
674 * type [I] Flag for value type
675 * data [I] Address of value data
676 * count [I] Size of value data
679 * Success: ERROR_SUCCESS
680 * Failure: Error code
683 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
684 * NT does definitely care (aj)
686 DWORD WINAPI RegSetValueExW( HKEY hkey, LPCWSTR name, DWORD reserved,
687 DWORD type, CONST BYTE *data, DWORD count )
689 UNICODE_STRING nameW;
691 if (!is_version_nt()) /* win95 */
693 if (type == REG_SZ) count = (strlenW( (WCHAR *)data ) + 1) * sizeof(WCHAR);
695 else if (count && is_string(type))
697 LPCWSTR str = (LPCWSTR)data;
698 /* if user forgot to count terminating null, add it (yes NT does this) */
699 if (str[count / sizeof(WCHAR) - 1] && !str[count / sizeof(WCHAR)])
700 count += sizeof(WCHAR);
703 RtlInitUnicodeString( &nameW, name );
704 return RtlNtStatusToDosError( NtSetValueKey( hkey, &nameW, 0, type, data, count ) );
708 /******************************************************************************
709 * RegSetValueExA [ADVAPI32.@]
711 DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
712 CONST BYTE *data, DWORD count )
718 if (!is_version_nt()) /* win95 */
720 if (type == REG_SZ) count = strlen(data) + 1;
722 else if (count && is_string(type))
724 /* if user forgot to count terminating null, add it (yes NT does this) */
725 if (data[count-1] && !data[count]) count++;
728 if (is_string( type )) /* need to convert to Unicode */
731 RtlMultiByteToUnicodeSize( &lenW, data, count );
732 if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW ))) return ERROR_OUTOFMEMORY;
733 RtlMultiByteToUnicodeN( dataW, lenW, NULL, data, count );
735 data = (BYTE *)dataW;
738 RtlInitAnsiString( &nameA, name );
739 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
742 status = NtSetValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString, 0, type, data, count );
744 if (dataW) HeapFree( GetProcessHeap(), 0, dataW );
745 return RtlNtStatusToDosError( status );
749 /******************************************************************************
750 * RegSetValueW [ADVAPI32.@]
752 DWORD WINAPI RegSetValueW( HKEY hkey, LPCWSTR name, DWORD type, LPCWSTR data, DWORD count )
757 TRACE("(0x%x,%s,%ld,%s,%ld)\n", hkey, debugstr_w(name), type, debugstr_w(data), count );
759 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
761 if (name && name[0]) /* need to create the subkey */
763 if ((ret = RegCreateKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
766 ret = RegSetValueExW( subkey, NULL, 0, REG_SZ, (LPBYTE)data,
767 (strlenW( data ) + 1) * sizeof(WCHAR) );
768 if (subkey != hkey) RegCloseKey( subkey );
773 /******************************************************************************
774 * RegSetValueA [ADVAPI32.@]
776 DWORD WINAPI RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
781 TRACE("(0x%x,%s,%ld,%s,%ld)\n", hkey, debugstr_a(name), type, debugstr_a(data), count );
783 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
785 if (name && name[0]) /* need to create the subkey */
787 if ((ret = RegCreateKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
789 ret = RegSetValueExA( subkey, NULL, 0, REG_SZ, (LPBYTE)data, strlen(data)+1 );
790 if (subkey != hkey) RegCloseKey( subkey );
796 /******************************************************************************
797 * RegQueryValueExW [ADVAPI32.@]
799 * Retrieves type and data for a specified name associated with an open key
802 * hkey [I] Handle of key to query
803 * name [I] Name of value to query
804 * reserved [I] Reserved - must be NULL
805 * type [O] Address of buffer for value type. If NULL, the type
807 * data [O] Address of data buffer. If NULL, the actual data is
809 * count [I/O] Address of data buffer size
812 * ERROR_SUCCESS: Success
813 * ERROR_MORE_DATA: !!! if the specified buffer is not big enough to hold the data
814 * buffer is left untouched. The MS-documentation is wrong (js) !!!
816 DWORD WINAPI RegQueryValueExW( HKEY hkey, LPCWSTR name, LPDWORD reserved, LPDWORD type,
817 LPBYTE data, LPDWORD count )
820 UNICODE_STRING name_str;
822 char buffer[256], *buf_ptr = buffer;
823 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
824 static const int info_size = info->Data - (UCHAR *)info;
826 TRACE("(0x%x,%s,%p,%p,%p,%p=%ld)\n",
827 hkey, debugstr_w(name), reserved, type, data, count, count ? *count : 0 );
829 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
831 RtlInitUnicodeString( &name_str, name );
833 if (data) total_size = min( sizeof(buffer), *count + info_size );
834 else total_size = info_size;
836 status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
837 buffer, total_size, &total_size );
838 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
842 /* retry with a dynamically allocated buffer */
843 while (status == STATUS_BUFFER_OVERFLOW && total_size - info_size <= *count)
845 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
846 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
847 return ERROR_NOT_ENOUGH_MEMORY;
848 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
849 status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
850 buf_ptr, total_size, &total_size );
855 memcpy( data, buf_ptr + info_size, total_size - info_size );
856 /* if the type is REG_SZ and data is not 0-terminated
857 * and there is enough space in the buffer NT appends a \0 */
858 if (total_size - info_size <= *count-sizeof(WCHAR) && is_string(info->Type))
860 WCHAR *ptr = (WCHAR *)(data + total_size - info_size);
861 if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
864 else if (status != STATUS_BUFFER_OVERFLOW) goto done;
866 else status = STATUS_SUCCESS;
868 if (type) *type = info->Type;
869 if (count) *count = total_size - info_size;
872 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
873 return RtlNtStatusToDosError(status);
877 /******************************************************************************
878 * RegQueryValueExA [ADVAPI32.@]
881 * the documentation is wrong: if the buffer is too small it remains untouched
883 DWORD WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
884 LPBYTE data, LPDWORD count )
889 char buffer[256], *buf_ptr = buffer;
890 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
891 static const int info_size = info->Data - (UCHAR *)info;
893 TRACE("(0x%x,%s,%p,%p,%p,%p=%ld)\n",
894 hkey, debugstr_a(name), reserved, type, data, count, count ? *count : 0 );
896 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
898 RtlInitAnsiString( &nameA, name );
899 if ((status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
901 return RtlNtStatusToDosError(status);
903 status = NtQueryValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString,
904 KeyValuePartialInformation, buffer, sizeof(buffer), &total_size );
905 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
907 /* we need to fetch the contents for a string type even if not requested,
908 * because we need to compute the length of the ASCII string. */
909 if (data || is_string(info->Type))
911 /* retry with a dynamically allocated buffer */
912 while (status == STATUS_BUFFER_OVERFLOW)
914 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
915 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
917 status = STATUS_NO_MEMORY;
920 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
921 status = NtQueryValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString,
922 KeyValuePartialInformation, buf_ptr, total_size, &total_size );
925 if (status) goto done;
927 if (is_string(info->Type))
931 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info_size),
932 total_size - info_size );
935 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
938 RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info_size),
939 total_size - info_size );
940 /* if the type is REG_SZ and data is not 0-terminated
941 * and there is enough space in the buffer NT appends a \0 */
942 if (len < *count && data[len-1]) data[len] = 0;
945 total_size = len + info_size;
949 if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW;
950 else memcpy( data, buf_ptr + info_size, total_size - info_size );
953 else status = STATUS_SUCCESS;
955 if (type) *type = info->Type;
956 if (count) *count = total_size - info_size;
959 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
960 return RtlNtStatusToDosError(status);
964 /******************************************************************************
965 * RegQueryValueW [ADVAPI32.@]
967 DWORD WINAPI RegQueryValueW( HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count )
972 TRACE("(%x,%s,%p,%ld)\n", hkey, debugstr_w(name), data, count ? *count : 0 );
976 if ((ret = RegOpenKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
978 ret = RegQueryValueExW( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
979 if (subkey != hkey) RegCloseKey( subkey );
980 if (ret == ERROR_FILE_NOT_FOUND)
982 /* return empty string if default value not found */
984 if (count) *count = 1;
991 /******************************************************************************
992 * RegQueryValueA [ADVAPI32.@]
994 DWORD WINAPI RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
999 TRACE("(%x,%s,%p,%ld)\n", hkey, debugstr_a(name), data, count ? *count : 0 );
1001 if (name && name[0])
1003 if ((ret = RegOpenKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
1005 ret = RegQueryValueExA( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
1006 if (subkey != hkey) RegCloseKey( subkey );
1007 if (ret == ERROR_FILE_NOT_FOUND)
1009 /* return empty string if default value not found */
1010 if (data) *data = 0;
1011 if (count) *count = 1;
1012 ret = ERROR_SUCCESS;
1018 /******************************************************************************
1019 * RegEnumValueW [ADVAPI32.@]
1022 * hkey [I] Handle to key to query
1023 * index [I] Index of value to query
1024 * value [O] Value string
1025 * val_count [I/O] Size of value buffer (in wchars)
1026 * reserved [I] Reserved
1027 * type [O] Type code
1028 * data [O] Value data
1029 * count [I/O] Size of data buffer (in bytes)
1032 DWORD WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_count,
1033 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
1037 char buffer[256], *buf_ptr = buffer;
1038 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
1039 static const int info_size = (char *)info->Name - (char *)info;
1041 TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
1042 hkey, index, value, val_count, reserved, type, data, count );
1044 /* NT only checks count, not val_count */
1045 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
1047 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
1048 if (data) total_size += *count;
1049 total_size = min( sizeof(buffer), total_size );
1051 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1052 buffer, total_size, &total_size );
1053 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
1057 /* retry with a dynamically allocated buffer */
1058 while (status == STATUS_BUFFER_OVERFLOW)
1060 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1061 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
1062 return ERROR_NOT_ENOUGH_MEMORY;
1063 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
1064 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1065 buf_ptr, total_size, &total_size );
1068 if (status) goto done;
1072 if (info->NameLength/sizeof(WCHAR) >= *val_count)
1074 status = STATUS_BUFFER_OVERFLOW;
1077 memcpy( value, info->Name, info->NameLength );
1078 *val_count = info->NameLength / sizeof(WCHAR);
1079 value[*val_count] = 0;
1084 if (total_size - info->DataOffset > *count)
1086 status = STATUS_BUFFER_OVERFLOW;
1089 memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
1090 if (total_size - info->DataOffset <= *count-sizeof(WCHAR) && is_string(info->Type))
1092 /* if the type is REG_SZ and data is not 0-terminated
1093 * and there is enough space in the buffer NT appends a \0 */
1094 WCHAR *ptr = (WCHAR *)(data + total_size - info->DataOffset);
1095 if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
1099 else status = STATUS_SUCCESS;
1101 if (type) *type = info->Type;
1102 if (count) *count = info->DataLength;
1105 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1106 return RtlNtStatusToDosError(status);
1110 /******************************************************************************
1111 * RegEnumValueA [ADVAPI32.@]
1113 DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
1114 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
1118 char buffer[256], *buf_ptr = buffer;
1119 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
1120 static const int info_size = (char *)info->Name - (char *)info;
1122 TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
1123 hkey, index, value, val_count, reserved, type, data, count );
1125 /* NT only checks count, not val_count */
1126 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
1128 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
1129 if (data) total_size += *count;
1130 total_size = min( sizeof(buffer), total_size );
1132 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1133 buffer, total_size, &total_size );
1134 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
1136 /* we need to fetch the contents for a string type even if not requested,
1137 * because we need to compute the length of the ASCII string. */
1138 if (value || data || is_string(info->Type))
1140 /* retry with a dynamically allocated buffer */
1141 while (status == STATUS_BUFFER_OVERFLOW)
1143 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1144 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
1145 return ERROR_NOT_ENOUGH_MEMORY;
1146 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
1147 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1148 buf_ptr, total_size, &total_size );
1151 if (status) goto done;
1157 RtlUnicodeToMultiByteSize( &len, info->Name, info->NameLength );
1158 if (len >= *val_count)
1160 status = STATUS_BUFFER_OVERFLOW;
1163 RtlUnicodeToMultiByteN( value, len, NULL, info->Name, info->NameLength );
1168 if (is_string(info->Type))
1171 RtlUnicodeToMultiByteSize( &len, (WCHAR *)(buf_ptr + info->DataOffset),
1172 total_size - info->DataOffset );
1177 status = STATUS_BUFFER_OVERFLOW;
1180 RtlUnicodeToMultiByteN( data, len, NULL, (WCHAR *)(buf_ptr + info->DataOffset),
1181 total_size - info->DataOffset );
1182 /* if the type is REG_SZ and data is not 0-terminated
1183 * and there is enough space in the buffer NT appends a \0 */
1184 if (len < *count && data[len-1]) data[len] = 0;
1186 info->DataLength = len;
1190 if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
1191 else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
1194 else status = STATUS_SUCCESS;
1196 if (type) *type = info->Type;
1197 if (count) *count = info->DataLength;
1200 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1201 return RtlNtStatusToDosError(status);
1206 /******************************************************************************
1207 * RegDeleteValueW [ADVAPI32.@]
1210 * hkey [I] handle to key
1211 * name [I] name of value to delete
1216 DWORD WINAPI RegDeleteValueW( HKEY hkey, LPCWSTR name )
1218 UNICODE_STRING nameW;
1219 RtlInitUnicodeString( &nameW, name );
1220 return RtlNtStatusToDosError( NtDeleteValueKey( hkey, &nameW ) );
1224 /******************************************************************************
1225 * RegDeleteValueA [ADVAPI32.@]
1227 DWORD WINAPI RegDeleteValueA( HKEY hkey, LPCSTR name )
1232 RtlInitAnsiString( &nameA, name );
1233 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
1236 status = NtDeleteValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString );
1238 return RtlNtStatusToDosError( status );
1242 /******************************************************************************
1243 * RegLoadKeyW [ADVAPI32.@]
1246 * hkey [I] Handle of open key
1247 * subkey [I] Address of name of subkey
1248 * filename [I] Address of filename for registry information
1250 LONG WINAPI RegLoadKeyW( HKEY hkey, LPCWSTR subkey, LPCWSTR filename )
1253 DWORD ret, len, err = GetLastError();
1255 TRACE( "(%x,%s,%s)\n", hkey, debugstr_w(subkey), debugstr_w(filename) );
1257 if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
1258 if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
1260 len = strlenW( subkey ) * sizeof(WCHAR);
1261 if (len > MAX_PATH*sizeof(WCHAR)) return ERROR_INVALID_PARAMETER;
1263 if ((file = CreateFileW( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1264 FILE_ATTRIBUTE_NORMAL, 0 )) == INVALID_HANDLE_VALUE)
1266 ret = GetLastError();
1270 SERVER_START_REQ( load_registry )
1274 wine_server_add_data( req, subkey, len );
1275 ret = RtlNtStatusToDosError( wine_server_call(req) );
1278 CloseHandle( file );
1281 SetLastError( err ); /* restore the last error code */
1286 /******************************************************************************
1287 * RegLoadKeyA [ADVAPI32.@]
1289 LONG WINAPI RegLoadKeyA( HKEY hkey, LPCSTR subkey, LPCSTR filename )
1291 WCHAR buffer[MAX_PATH];
1293 DWORD ret, len, err = GetLastError();
1295 TRACE( "(%x,%s,%s)\n", hkey, debugstr_a(subkey), debugstr_a(filename) );
1297 if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
1298 if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
1300 if (!(len = MultiByteToWideChar( CP_ACP, 0, subkey, strlen(subkey), buffer, MAX_PATH )))
1301 return ERROR_INVALID_PARAMETER;
1303 if ((file = CreateFileA( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1304 FILE_ATTRIBUTE_NORMAL, 0 )) == INVALID_HANDLE_VALUE)
1306 ret = GetLastError();
1310 SERVER_START_REQ( load_registry )
1314 wine_server_add_data( req, buffer, len * sizeof(WCHAR) );
1315 ret = RtlNtStatusToDosError( wine_server_call(req) );
1318 CloseHandle( file );
1321 SetLastError( err ); /* restore the last error code */
1326 /******************************************************************************
1327 * RegSaveKeyA [ADVAPI32.@]
1330 * hkey [I] Handle of key where save begins
1331 * lpFile [I] Address of filename to save to
1332 * sa [I] Address of security structure
1334 LONG WINAPI RegSaveKeyA( HKEY hkey, LPCSTR file, LPSECURITY_ATTRIBUTES sa )
1342 TRACE( "(%x,%s,%p)\n", hkey, debugstr_a(file), sa );
1344 if (!file || !*file) return ERROR_INVALID_PARAMETER;
1346 err = GetLastError();
1347 GetFullPathNameA( file, sizeof(buffer), buffer, &name );
1350 sprintf( name, "reg%04x.tmp", count++ );
1351 handle = CreateFileA( buffer, GENERIC_WRITE, 0, NULL,
1352 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1353 if (handle != INVALID_HANDLE_VALUE) break;
1354 if ((ret = GetLastError()) != ERROR_ALREADY_EXISTS) goto done;
1356 /* Something gone haywire ? Please report if this happens abnormally */
1358 MESSAGE("Wow, we are already fiddling with a temp file %s with an ordinal as high as %d !\nYou might want to delete all corresponding temp files in that directory.\n", buffer, count);
1361 SERVER_START_REQ( save_registry )
1365 ret = RtlNtStatusToDosError( wine_server_call( req ) );
1369 CloseHandle( handle );
1372 if (!MoveFileExA( buffer, file, MOVEFILE_REPLACE_EXISTING ))
1374 ERR( "Failed to move %s to %s\n", buffer, file );
1375 ret = GetLastError();
1378 if (ret) DeleteFileA( buffer );
1381 SetLastError( err ); /* restore last error code */
1386 /******************************************************************************
1387 * RegSaveKeyW [ADVAPI32.@]
1389 LONG WINAPI RegSaveKeyW( HKEY hkey, LPCWSTR file, LPSECURITY_ATTRIBUTES sa )
1391 LPSTR fileA = HEAP_strdupWtoA( GetProcessHeap(), 0, file );
1392 DWORD ret = RegSaveKeyA( hkey, fileA, sa );
1393 if (fileA) HeapFree( GetProcessHeap(), 0, fileA );
1398 /******************************************************************************
1399 * RegRestoreKeyW [ADVAPI32.@]
1402 * hkey [I] Handle of key where restore begins
1403 * lpFile [I] Address of filename containing saved tree
1404 * dwFlags [I] Optional flags
1406 LONG WINAPI RegRestoreKeyW( HKEY hkey, LPCWSTR lpFile, DWORD dwFlags )
1408 TRACE("(%x,%s,%ld)\n",hkey,debugstr_w(lpFile),dwFlags);
1410 /* It seems to do this check before the hkey check */
1411 if (!lpFile || !*lpFile)
1412 return ERROR_INVALID_PARAMETER;
1414 FIXME("(%x,%s,%ld): stub\n",hkey,debugstr_w(lpFile),dwFlags);
1416 /* Check for file existence */
1418 return ERROR_SUCCESS;
1422 /******************************************************************************
1423 * RegRestoreKeyA [ADVAPI32.@]
1425 LONG WINAPI RegRestoreKeyA( HKEY hkey, LPCSTR lpFile, DWORD dwFlags )
1427 LPWSTR lpFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpFile );
1428 LONG ret = RegRestoreKeyW( hkey, lpFileW, dwFlags );
1429 HeapFree( GetProcessHeap(), 0, lpFileW );
1434 /******************************************************************************
1435 * RegUnLoadKeyW [ADVAPI32.@]
1438 * hkey [I] Handle of open key
1439 * lpSubKey [I] Address of name of subkey to unload
1441 LONG WINAPI RegUnLoadKeyW( HKEY hkey, LPCWSTR lpSubKey )
1443 FIXME("(%x,%s): stub\n",hkey, debugstr_w(lpSubKey));
1444 return ERROR_SUCCESS;
1448 /******************************************************************************
1449 * RegUnLoadKeyA [ADVAPI32.@]
1451 LONG WINAPI RegUnLoadKeyA( HKEY hkey, LPCSTR lpSubKey )
1453 LPWSTR lpSubKeyW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpSubKey );
1454 LONG ret = RegUnLoadKeyW( hkey, lpSubKeyW );
1455 if(lpSubKeyW) HeapFree( GetProcessHeap(), 0, lpSubKeyW);
1460 /******************************************************************************
1461 * RegReplaceKeyW [ADVAPI32.@]
1464 * hkey [I] Handle of open key
1465 * lpSubKey [I] Address of name of subkey
1466 * lpNewFile [I] Address of filename for file with new data
1467 * lpOldFile [I] Address of filename for backup file
1469 LONG WINAPI RegReplaceKeyW( HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpNewFile,
1472 FIXME("(%x,%s,%s,%s): stub\n", hkey, debugstr_w(lpSubKey),
1473 debugstr_w(lpNewFile),debugstr_w(lpOldFile));
1474 return ERROR_SUCCESS;
1478 /******************************************************************************
1479 * RegReplaceKeyA [ADVAPI32.@]
1481 LONG WINAPI RegReplaceKeyA( HKEY hkey, LPCSTR lpSubKey, LPCSTR lpNewFile,
1484 LPWSTR lpSubKeyW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpSubKey );
1485 LPWSTR lpNewFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpNewFile );
1486 LPWSTR lpOldFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpOldFile );
1487 LONG ret = RegReplaceKeyW( hkey, lpSubKeyW, lpNewFileW, lpOldFileW );
1488 HeapFree( GetProcessHeap(), 0, lpOldFileW );
1489 HeapFree( GetProcessHeap(), 0, lpNewFileW );
1490 HeapFree( GetProcessHeap(), 0, lpSubKeyW );
1495 /******************************************************************************
1496 * RegSetKeySecurity [ADVAPI32.@]
1499 * hkey [I] Open handle of key to set
1500 * SecurityInfo [I] Descriptor contents
1501 * pSecurityDesc [I] Address of descriptor for key
1503 LONG WINAPI RegSetKeySecurity( HKEY hkey, SECURITY_INFORMATION SecurityInfo,
1504 PSECURITY_DESCRIPTOR pSecurityDesc )
1506 TRACE("(%x,%ld,%p)\n",hkey,SecurityInfo,pSecurityDesc);
1508 /* It seems to perform this check before the hkey check */
1509 if ((SecurityInfo & OWNER_SECURITY_INFORMATION) ||
1510 (SecurityInfo & GROUP_SECURITY_INFORMATION) ||
1511 (SecurityInfo & DACL_SECURITY_INFORMATION) ||
1512 (SecurityInfo & SACL_SECURITY_INFORMATION)) {
1515 return ERROR_INVALID_PARAMETER;
1518 return ERROR_INVALID_PARAMETER;
1520 FIXME(":(%x,%ld,%p): stub\n",hkey,SecurityInfo,pSecurityDesc);
1522 return ERROR_SUCCESS;
1526 /******************************************************************************
1527 * RegGetKeySecurity [ADVAPI32.@]
1528 * Retrieves a copy of security descriptor protecting the registry key
1531 * hkey [I] Open handle of key to set
1532 * SecurityInformation [I] Descriptor contents
1533 * pSecurityDescriptor [O] Address of descriptor for key
1534 * lpcbSecurityDescriptor [I/O] Address of size of buffer and description
1537 * Success: ERROR_SUCCESS
1538 * Failure: Error code
1540 LONG WINAPI RegGetKeySecurity( HKEY hkey, SECURITY_INFORMATION SecurityInformation,
1541 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1542 LPDWORD lpcbSecurityDescriptor )
1544 TRACE("(%x,%ld,%p,%ld)\n",hkey,SecurityInformation,pSecurityDescriptor,
1545 lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0);
1547 /* FIXME: Check for valid SecurityInformation values */
1549 if (*lpcbSecurityDescriptor < sizeof(SECURITY_DESCRIPTOR))
1550 return ERROR_INSUFFICIENT_BUFFER;
1552 FIXME("(%x,%ld,%p,%ld): stub\n",hkey,SecurityInformation,
1553 pSecurityDescriptor,lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0);
1555 /* Do not leave security descriptor filled with garbage */
1556 RtlCreateSecurityDescriptor(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
1558 return ERROR_SUCCESS;
1562 /******************************************************************************
1563 * RegFlushKey [ADVAPI32.@]
1564 * Immediately writes key to registry.
1565 * Only returns after data has been written to disk.
1567 * FIXME: does it really wait until data is written ?
1570 * hkey [I] Handle of key to write
1573 * Success: ERROR_SUCCESS
1574 * Failure: Error code
1576 DWORD WINAPI RegFlushKey( HKEY hkey )
1578 FIXME( "(%x): stub\n", hkey );
1579 return ERROR_SUCCESS;
1583 /******************************************************************************
1584 * RegConnectRegistryW [ADVAPI32.@]
1587 * lpMachineName [I] Address of name of remote computer
1588 * hHey [I] Predefined registry handle
1589 * phkResult [I] Address of buffer for remote registry handle
1591 LONG WINAPI RegConnectRegistryW( LPCWSTR lpMachineName, HKEY hKey,
1594 TRACE("(%s,%x,%p): stub\n",debugstr_w(lpMachineName),hKey,phkResult);
1596 if (!lpMachineName || !*lpMachineName) {
1597 /* Use the local machine name */
1598 return RegOpenKeyA( hKey, "", phkResult );
1601 FIXME("Cannot connect to %s\n",debugstr_w(lpMachineName));
1602 return ERROR_BAD_NETPATH;
1606 /******************************************************************************
1607 * RegConnectRegistryA [ADVAPI32.@]
1609 LONG WINAPI RegConnectRegistryA( LPCSTR machine, HKEY hkey, LPHKEY reskey )
1611 LPWSTR machineW = HEAP_strdupAtoW( GetProcessHeap(), 0, machine );
1612 DWORD ret = RegConnectRegistryW( machineW, hkey, reskey );
1613 HeapFree( GetProcessHeap(), 0, machineW );
1618 /******************************************************************************
1619 * RegNotifyChangeKeyValue [ADVAPI32.@]
1622 * hkey [I] Handle of key to watch
1623 * fWatchSubTree [I] Flag for subkey notification
1624 * fdwNotifyFilter [I] Changes to be reported
1625 * hEvent [I] Handle of signaled event
1626 * fAsync [I] Flag for asynchronous reporting
1628 LONG WINAPI RegNotifyChangeKeyValue( HKEY hkey, BOOL fWatchSubTree,
1629 DWORD fdwNotifyFilter, HANDLE hEvent,
1632 FIXME("(%x,%i,%ld,%x,%i): stub\n",hkey,fWatchSubTree,fdwNotifyFilter,
1634 return ERROR_SUCCESS;