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.
22 #include "wine/unicode.h"
24 #include "wine/server.h"
25 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(reg);
30 /* check if value type needs string conversion (Ansi<->Unicode) */
31 static inline int is_string( DWORD type )
33 return (type == REG_SZ) || (type == REG_EXPAND_SZ) || (type == REG_MULTI_SZ);
37 /******************************************************************************
38 * RegCreateKeyExW [ADVAPI32.@]
41 * hkey [I] Handle of an open key
42 * name [I] Address of subkey name
43 * reserved [I] Reserved - must be 0
44 * class [I] Address of class string
45 * options [I] Special options flag
46 * access [I] Desired security access
47 * sa [I] Address of key security structure
48 * retkey [O] Address of buffer for opened handle
49 * dispos [O] Receives REG_CREATED_NEW_KEY or REG_OPENED_EXISTING_KEY
52 * in case of failing retkey remains untouched
54 DWORD WINAPI RegCreateKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, LPWSTR class,
55 DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa,
56 LPHKEY retkey, LPDWORD dispos )
58 OBJECT_ATTRIBUTES attr;
59 UNICODE_STRING nameW, classW;
61 if (reserved) return ERROR_INVALID_PARAMETER;
62 if (!(access & KEY_ALL_ACCESS) || (access & ~KEY_ALL_ACCESS)) return ERROR_ACCESS_DENIED;
64 attr.Length = sizeof(attr);
65 attr.RootDirectory = hkey;
66 attr.ObjectName = &nameW;
68 attr.SecurityDescriptor = NULL;
69 attr.SecurityQualityOfService = NULL;
70 RtlInitUnicodeString( &nameW, name );
71 RtlInitUnicodeString( &classW, class );
73 return RtlNtStatusToDosError( NtCreateKey( retkey, access, &attr, 0,
74 &classW, options, dispos ) );
78 /******************************************************************************
79 * RegCreateKeyExA [ADVAPI32.@]
81 DWORD WINAPI RegCreateKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, LPSTR class,
82 DWORD options, REGSAM access, SECURITY_ATTRIBUTES *sa,
83 LPHKEY retkey, LPDWORD dispos )
85 OBJECT_ATTRIBUTES attr;
86 UNICODE_STRING classW;
87 ANSI_STRING nameA, classA;
90 if (reserved) return ERROR_INVALID_PARAMETER;
91 if (!(access & KEY_ALL_ACCESS) || (access & ~KEY_ALL_ACCESS)) return ERROR_ACCESS_DENIED;
93 attr.Length = sizeof(attr);
94 attr.RootDirectory = hkey;
95 attr.ObjectName = &NtCurrentTeb()->StaticUnicodeString;
97 attr.SecurityDescriptor = NULL;
98 attr.SecurityQualityOfService = NULL;
99 RtlInitAnsiString( &nameA, name );
100 RtlInitAnsiString( &classA, class );
102 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
105 if (!(status = RtlAnsiStringToUnicodeString( &classW, &classA, TRUE )))
107 status = NtCreateKey( retkey, access, &attr, 0, &classW, options, dispos );
108 RtlFreeUnicodeString( &classW );
111 return RtlNtStatusToDosError( status );
115 /******************************************************************************
116 * RegCreateKeyW [ADVAPI32.@]
118 DWORD WINAPI RegCreateKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
120 /* FIXME: previous implementation converted ERROR_INVALID_HANDLE to ERROR_BADKEY, */
121 /* but at least my version of NT (4.0 SP5) doesn't do this. -- AJ */
122 return RegCreateKeyExW( hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
123 KEY_ALL_ACCESS, NULL, retkey, NULL );
127 /******************************************************************************
128 * RegCreateKeyA [ADVAPI32.@]
130 DWORD WINAPI RegCreateKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
132 return RegCreateKeyExA( hkey, name, 0, NULL, REG_OPTION_NON_VOLATILE,
133 KEY_ALL_ACCESS, NULL, retkey, NULL );
138 /******************************************************************************
139 * RegOpenKeyExW [ADVAPI32.@]
141 * Opens the specified key
143 * Unlike RegCreateKeyEx, this does not create the key if it does not exist.
146 * hkey [I] Handle of open key
147 * name [I] Name of subkey to open
148 * reserved [I] Reserved - must be zero
149 * access [I] Security access mask
150 * retkey [O] Handle to open key
153 * Success: ERROR_SUCCESS
154 * Failure: Error code
157 * in case of failing is retkey = 0
159 DWORD WINAPI RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, REGSAM access, LPHKEY retkey )
161 OBJECT_ATTRIBUTES attr;
162 UNICODE_STRING nameW;
164 attr.Length = sizeof(attr);
165 attr.RootDirectory = hkey;
166 attr.ObjectName = &nameW;
168 attr.SecurityDescriptor = NULL;
169 attr.SecurityQualityOfService = NULL;
170 RtlInitUnicodeString( &nameW, name );
171 return RtlNtStatusToDosError( NtOpenKey( retkey, access, &attr ) );
175 /******************************************************************************
176 * RegOpenKeyExA [ADVAPI32.@]
178 DWORD WINAPI RegOpenKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, REGSAM access, LPHKEY retkey )
180 OBJECT_ATTRIBUTES attr;
184 attr.Length = sizeof(attr);
185 attr.RootDirectory = hkey;
186 attr.ObjectName = &NtCurrentTeb()->StaticUnicodeString;
188 attr.SecurityDescriptor = NULL;
189 attr.SecurityQualityOfService = NULL;
191 RtlInitAnsiString( &nameA, name );
192 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
195 status = NtOpenKey( retkey, access, &attr );
197 return RtlNtStatusToDosError( status );
201 /******************************************************************************
202 * RegOpenKeyW [ADVAPI32.@]
205 * hkey [I] Handle of open key
206 * name [I] Address of name of subkey to open
207 * retkey [O] Handle to open key
210 * Success: ERROR_SUCCESS
211 * Failure: Error code
214 * in case of failing is retkey = 0
216 DWORD WINAPI RegOpenKeyW( HKEY hkey, LPCWSTR name, LPHKEY retkey )
218 return RegOpenKeyExW( hkey, name, 0, KEY_ALL_ACCESS, retkey );
222 /******************************************************************************
223 * RegOpenKeyA [ADVAPI32.@]
225 DWORD WINAPI RegOpenKeyA( HKEY hkey, LPCSTR name, LPHKEY retkey )
227 return RegOpenKeyExA( hkey, name, 0, KEY_ALL_ACCESS, retkey );
231 /******************************************************************************
232 * RegOpenCurrentUser [ADVAPI32.@]
233 * FIXME: This function is supposed to retrieve a handle to the
234 * HKEY_CURRENT_USER for the user the current thread is impersonating.
235 * Since Wine does not currently allow threads to impersonate other users,
236 * this stub should work fine.
238 DWORD WINAPI RegOpenCurrentUser( REGSAM access, PHKEY retkey )
240 return RegOpenKeyExA( HKEY_CURRENT_USER, "", 0, access, retkey );
245 /******************************************************************************
246 * RegEnumKeyExW [ADVAPI32.@]
249 * hkey [I] Handle to key to enumerate
250 * index [I] Index of subkey to enumerate
251 * name [O] Buffer for subkey name
252 * name_len [O] Size of subkey buffer
253 * reserved [I] Reserved
254 * class [O] Buffer for class string
255 * class_len [O] Size of class buffer
256 * ft [O] Time key last written to
258 DWORD WINAPI RegEnumKeyExW( HKEY hkey, DWORD index, LPWSTR name, LPDWORD name_len,
259 LPDWORD reserved, LPWSTR class, LPDWORD class_len, FILETIME *ft )
262 char buffer[256], *buf_ptr = buffer;
263 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
266 TRACE( "(0x%x,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey, index, name, name_len,
267 name_len ? *name_len : -1, reserved, class, class_len, ft );
269 if (reserved) return ERROR_INVALID_PARAMETER;
271 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
272 buffer, sizeof(buffer), &total_size );
274 while (status == STATUS_BUFFER_OVERFLOW)
276 /* retry with a dynamically allocated buffer */
277 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
278 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
279 return ERROR_NOT_ENOUGH_MEMORY;
280 info = (KEY_NODE_INFORMATION *)buf_ptr;
281 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
282 buf_ptr, total_size, &total_size );
287 DWORD len = info->NameLength / sizeof(WCHAR);
288 DWORD cls_len = info->ClassLength / sizeof(WCHAR);
290 if (ft) *ft = info->LastWriteTime;
292 if (len >= *name_len || (class_len && (cls_len >= *class_len)))
293 status = STATUS_BUFFER_OVERFLOW;
297 memcpy( name, info->Name, info->NameLength );
301 *class_len = cls_len;
304 memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
311 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
312 return RtlNtStatusToDosError( status );
316 /******************************************************************************
317 * RegEnumKeyExA [ADVAPI32.@]
319 DWORD WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_len,
320 LPDWORD reserved, LPSTR class, LPDWORD class_len, FILETIME *ft )
323 char buffer[256], *buf_ptr = buffer;
324 KEY_NODE_INFORMATION *info = (KEY_NODE_INFORMATION *)buffer;
327 TRACE( "(0x%x,%ld,%p,%p(%ld),%p,%p,%p,%p)\n", hkey, index, name, name_len,
328 name_len ? *name_len : -1, reserved, class, class_len, ft );
330 if (reserved) return ERROR_INVALID_PARAMETER;
332 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
333 buffer, sizeof(buffer), &total_size );
335 while (status == STATUS_BUFFER_OVERFLOW)
337 /* retry with a dynamically allocated buffer */
338 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
339 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
340 return ERROR_NOT_ENOUGH_MEMORY;
341 info = (KEY_NODE_INFORMATION *)buf_ptr;
342 status = NtEnumerateKey( hkey, index, KeyNodeInformation,
343 buf_ptr, total_size, &total_size );
348 DWORD len = WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
349 NULL, 0, NULL, NULL );
350 DWORD cls_len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->ClassOffset),
351 info->ClassLength / sizeof(WCHAR),
352 NULL, 0, NULL, NULL );
354 if (ft) *ft = info->LastWriteTime;
356 if (len >= *name_len || (class_len && (cls_len >= *class_len)))
357 status = STATUS_BUFFER_OVERFLOW;
361 WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
362 name, len, NULL, NULL );
366 *class_len = cls_len;
369 WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->ClassOffset),
370 info->ClassLength / sizeof(WCHAR),
371 class, cls_len, NULL, NULL );
378 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
379 return RtlNtStatusToDosError( status );
383 /******************************************************************************
384 * RegEnumKeyW [ADVAPI32.@]
386 DWORD WINAPI RegEnumKeyW( HKEY hkey, DWORD index, LPWSTR name, DWORD name_len )
388 return RegEnumKeyExW( hkey, index, name, &name_len, NULL, NULL, NULL, NULL );
392 /******************************************************************************
393 * RegEnumKeyA [ADVAPI32.@]
395 DWORD WINAPI RegEnumKeyA( HKEY hkey, DWORD index, LPSTR name, DWORD name_len )
397 return RegEnumKeyExA( hkey, index, name, &name_len, NULL, NULL, NULL, NULL );
401 /******************************************************************************
402 * RegQueryInfoKeyW [ADVAPI32.@]
405 * hkey [I] Handle to key to query
406 * class [O] Buffer for class string
407 * class_len [O] Size of class string buffer
408 * reserved [I] Reserved
409 * subkeys [O] Buffer for number of subkeys
410 * max_subkey [O] Buffer for longest subkey name length
411 * max_class [O] Buffer for longest class string length
412 * values [O] Buffer for number of value entries
413 * max_value [O] Buffer for longest value name length
414 * max_data [O] Buffer for longest value data length
415 * security [O] Buffer for security descriptor length
416 * modif [O] Modification time
418 * - win95 allows class to be valid and class_len to be NULL
419 * - winnt returns ERROR_INVALID_PARAMETER if class is valid and class_len is NULL
420 * - both allow class to be NULL and class_len to be NULL
421 * (it's hard to test validity, so test !NULL instead)
423 DWORD WINAPI RegQueryInfoKeyW( HKEY hkey, LPWSTR class, LPDWORD class_len, LPDWORD reserved,
424 LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
425 LPDWORD values, LPDWORD max_value, LPDWORD max_data,
426 LPDWORD security, FILETIME *modif )
429 char buffer[256], *buf_ptr = buffer;
430 KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
433 TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
434 reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
436 if (class && !class_len && !(GetVersion() & 0x80000000 /*NT*/))
437 return ERROR_INVALID_PARAMETER;
439 status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
440 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
444 /* retry with a dynamically allocated buffer */
445 while (status == STATUS_BUFFER_OVERFLOW)
447 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
448 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
449 return ERROR_NOT_ENOUGH_MEMORY;
450 info = (KEY_FULL_INFORMATION *)buf_ptr;
451 status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
454 if (status) goto done;
456 if (class_len && (info->ClassLength/sizeof(WCHAR) + 1 > *class_len))
458 status = STATUS_BUFFER_OVERFLOW;
462 memcpy( class, buf_ptr + info->ClassOffset, info->ClassLength );
463 class[info->ClassLength/sizeof(WCHAR)] = 0;
466 else status = STATUS_SUCCESS;
468 if (class_len) *class_len = info->ClassLength / sizeof(WCHAR);
469 if (subkeys) *subkeys = info->SubKeys;
470 if (max_subkey) *max_subkey = info->MaxNameLen;
471 if (max_class) *max_class = info->MaxClassLen;
472 if (values) *values = info->Values;
473 if (max_value) *max_value = info->MaxValueNameLen;
474 if (max_data) *max_data = info->MaxValueDataLen;
475 if (modif) *modif = info->LastWriteTime;
478 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
479 return RtlNtStatusToDosError( status );
483 /******************************************************************************
484 * RegQueryInfoKeyA [ADVAPI32.@]
486 DWORD WINAPI RegQueryInfoKeyA( HKEY hkey, LPSTR class, LPDWORD class_len, LPDWORD reserved,
487 LPDWORD subkeys, LPDWORD max_subkey, LPDWORD max_class,
488 LPDWORD values, LPDWORD max_value, LPDWORD max_data,
489 LPDWORD security, FILETIME *modif )
492 char buffer[256], *buf_ptr = buffer;
493 KEY_FULL_INFORMATION *info = (KEY_FULL_INFORMATION *)buffer;
494 DWORD total_size, len;
496 TRACE( "(0x%x,%p,%ld,%p,%p,%p,%p,%p,%p,%p,%p)\n", hkey, class, class_len ? *class_len : 0,
497 reserved, subkeys, max_subkey, values, max_value, max_data, security, modif );
499 if (class && !class_len && !(GetVersion() & 0x80000000 /*NT*/))
500 return ERROR_INVALID_PARAMETER;
502 status = NtQueryKey( hkey, KeyFullInformation, buffer, sizeof(buffer), &total_size );
503 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
505 if (class || class_len)
507 /* retry with a dynamically allocated buffer */
508 while (status == STATUS_BUFFER_OVERFLOW)
510 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
511 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
512 return ERROR_NOT_ENOUGH_MEMORY;
513 info = (KEY_FULL_INFORMATION *)buf_ptr;
514 status = NtQueryKey( hkey, KeyFullInformation, buf_ptr, total_size, &total_size );
517 if (status) goto done;
519 len = WideCharToMultiByte( CP_ACP, 0,
520 (WCHAR *)(buf_ptr + info->ClassOffset),
521 info->ClassLength/sizeof(WCHAR),
522 NULL, 0, NULL, NULL );
525 if (len + 1 > *class_len) status = STATUS_BUFFER_OVERFLOW;
528 if (class && !status)
530 WideCharToMultiByte( CP_ACP, 0,
531 (WCHAR *)(buf_ptr + info->ClassOffset),
532 info->ClassLength/sizeof(WCHAR),
533 class, len, NULL, NULL );
537 else status = STATUS_SUCCESS;
539 if (subkeys) *subkeys = info->SubKeys;
540 if (max_subkey) *max_subkey = info->MaxNameLen;
541 if (max_class) *max_class = info->MaxClassLen;
542 if (values) *values = info->Values;
543 if (max_value) *max_value = info->MaxValueNameLen;
544 if (max_data) *max_data = info->MaxValueDataLen;
545 if (modif) *modif = info->LastWriteTime;
548 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
549 return RtlNtStatusToDosError( status );
553 /******************************************************************************
554 * RegCloseKey [ADVAPI32.@]
556 * Releases the handle of the specified key
559 * hkey [I] Handle of key to close
562 * Success: ERROR_SUCCESS
563 * Failure: Error code
565 DWORD WINAPI RegCloseKey( HKEY hkey )
567 if (!hkey || hkey >= 0x80000000) return ERROR_SUCCESS;
568 return RtlNtStatusToDosError( NtClose( hkey ) );
572 /******************************************************************************
573 * RegDeleteKeyW [ADVAPI32.@]
576 * hkey [I] Handle to open key
577 * name [I] Name of subkey to delete
580 * Success: ERROR_SUCCESS
581 * Failure: Error code
583 DWORD WINAPI RegDeleteKeyW( HKEY hkey, LPCWSTR name )
588 if (!name || !*name) return NtDeleteKey( hkey );
589 if (!(ret = RegOpenKeyExW( hkey, name, 0, 0, &tmp )))
591 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
598 /******************************************************************************
599 * RegDeleteKeyA [ADVAPI32.@]
601 DWORD WINAPI RegDeleteKeyA( HKEY hkey, LPCSTR name )
606 if (!name || !*name) return NtDeleteKey( hkey );
607 if (!(ret = RegOpenKeyExA( hkey, name, 0, 0, &tmp )))
609 ret = RtlNtStatusToDosError( NtDeleteKey( tmp ) );
617 /******************************************************************************
618 * RegSetValueExW [ADVAPI32.@]
620 * Sets the data and type of a value under a register key
623 * hkey [I] Handle of key to set value for
624 * name [I] Name of value to set
625 * reserved [I] Reserved - must be zero
626 * type [I] Flag for value type
627 * data [I] Address of value data
628 * count [I] Size of value data
631 * Success: ERROR_SUCCESS
632 * Failure: Error code
635 * win95 does not care about count for REG_SZ and finds out the len by itself (js)
636 * NT does definitely care (aj)
638 DWORD WINAPI RegSetValueExW( HKEY hkey, LPCWSTR name, DWORD reserved,
639 DWORD type, CONST BYTE *data, DWORD count )
641 UNICODE_STRING nameW;
643 if (GetVersion() & 0x80000000) /* win95 */
645 if (type == REG_SZ) count = (strlenW( (WCHAR *)data ) + 1) * sizeof(WCHAR);
647 else if (count && is_string(type))
649 LPCWSTR str = (LPCWSTR)data;
650 /* if user forgot to count terminating null, add it (yes NT does this) */
651 if (str[count / sizeof(WCHAR) - 1] && !str[count / sizeof(WCHAR)])
652 count += sizeof(WCHAR);
655 RtlInitUnicodeString( &nameW, name );
656 return RtlNtStatusToDosError( NtSetValueKey( hkey, &nameW, 0, type, data, count ) );
660 /******************************************************************************
661 * RegSetValueExA [ADVAPI32.@]
663 DWORD WINAPI RegSetValueExA( HKEY hkey, LPCSTR name, DWORD reserved, DWORD type,
664 CONST BYTE *data, DWORD count )
670 if (GetVersion() & 0x80000000) /* win95 */
672 if (type == REG_SZ) count = strlen(data) + 1;
674 else if (count && is_string(type))
676 /* if user forgot to count terminating null, add it (yes NT does this) */
677 if (data[count-1] && !data[count]) count++;
680 if (is_string( type )) /* need to convert to Unicode */
682 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, data, count, NULL, 0 );
683 if (!(dataW = HeapAlloc( GetProcessHeap(), 0, lenW*sizeof(WCHAR) )))
684 return ERROR_OUTOFMEMORY;
685 MultiByteToWideChar( CP_ACP, 0, data, count, dataW, lenW );
686 count = lenW * sizeof(WCHAR);
687 data = (BYTE *)dataW;
690 RtlInitAnsiString( &nameA, name );
691 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
694 status = NtSetValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString, 0, type, data, count );
696 if (dataW) HeapFree( GetProcessHeap(), 0, dataW );
697 return RtlNtStatusToDosError( status );
701 /******************************************************************************
702 * RegSetValueW [ADVAPI32.@]
704 DWORD WINAPI RegSetValueW( HKEY hkey, LPCWSTR name, DWORD type, LPCWSTR data, DWORD count )
709 TRACE("(0x%x,%s,%ld,%s,%ld)\n", hkey, debugstr_w(name), type, debugstr_w(data), count );
711 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
713 if (name && name[0]) /* need to create the subkey */
715 if ((ret = RegCreateKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
718 ret = RegSetValueExW( subkey, NULL, 0, REG_SZ, (LPBYTE)data,
719 (strlenW( data ) + 1) * sizeof(WCHAR) );
720 if (subkey != hkey) RegCloseKey( subkey );
725 /******************************************************************************
726 * RegSetValueA [ADVAPI32.@]
728 DWORD WINAPI RegSetValueA( HKEY hkey, LPCSTR name, DWORD type, LPCSTR data, DWORD count )
733 TRACE("(0x%x,%s,%ld,%s,%ld)\n", hkey, debugstr_a(name), type, debugstr_a(data), count );
735 if (type != REG_SZ) return ERROR_INVALID_PARAMETER;
737 if (name && name[0]) /* need to create the subkey */
739 if ((ret = RegCreateKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
741 ret = RegSetValueExA( subkey, NULL, 0, REG_SZ, (LPBYTE)data, strlen(data)+1 );
742 if (subkey != hkey) RegCloseKey( subkey );
748 /******************************************************************************
749 * RegQueryValueExW [ADVAPI32.@]
751 * Retrieves type and data for a specified name associated with an open key
754 * hkey [I] Handle of key to query
755 * name [I] Name of value to query
756 * reserved [I] Reserved - must be NULL
757 * type [O] Address of buffer for value type. If NULL, the type
759 * data [O] Address of data buffer. If NULL, the actual data is
761 * count [I/O] Address of data buffer size
764 * ERROR_SUCCESS: Success
765 * ERROR_MORE_DATA: !!! if the specified buffer is not big enough to hold the data
766 * buffer is left untouched. The MS-documentation is wrong (js) !!!
768 DWORD WINAPI RegQueryValueExW( HKEY hkey, LPCWSTR name, LPDWORD reserved, LPDWORD type,
769 LPBYTE data, LPDWORD count )
772 UNICODE_STRING name_str;
774 char buffer[256], *buf_ptr = buffer;
775 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
776 static const int info_size = sizeof(*info) - sizeof(info->Data);
778 TRACE("(0x%x,%s,%p,%p,%p,%p=%ld)\n",
779 hkey, debugstr_w(name), reserved, type, data, count, count ? *count : 0 );
781 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
783 RtlInitUnicodeString( &name_str, name );
785 if (data) total_size = min( sizeof(buffer), *count + info_size );
786 else total_size = info_size;
788 status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
789 buffer, total_size, &total_size );
790 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
794 /* retry with a dynamically allocated buffer */
795 while (status == STATUS_BUFFER_OVERFLOW && total_size - info_size <= *count)
797 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
798 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
799 return ERROR_NOT_ENOUGH_MEMORY;
800 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
801 status = NtQueryValueKey( hkey, &name_str, KeyValuePartialInformation,
802 buf_ptr, total_size, &total_size );
807 memcpy( data, buf_ptr + info_size, total_size - info_size );
808 /* if the type is REG_SZ and data is not 0-terminated
809 * and there is enough space in the buffer NT appends a \0 */
810 if (total_size - info_size <= *count-sizeof(WCHAR) && is_string(info->Type))
812 WCHAR *ptr = (WCHAR *)(data + total_size - info_size);
813 if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
816 else if (status != STATUS_BUFFER_OVERFLOW) goto done;
818 else status = STATUS_SUCCESS;
820 if (type) *type = info->Type;
821 if (count) *count = total_size - info_size;
824 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
825 return RtlNtStatusToDosError(status);
829 /******************************************************************************
830 * RegQueryValueExA [ADVAPI32.@]
833 * the documentation is wrong: if the buffer is too small it remains untouched
835 DWORD WINAPI RegQueryValueExA( HKEY hkey, LPCSTR name, LPDWORD reserved, LPDWORD type,
836 LPBYTE data, LPDWORD count )
841 char buffer[256], *buf_ptr = buffer;
842 KEY_VALUE_PARTIAL_INFORMATION *info = (KEY_VALUE_PARTIAL_INFORMATION *)buffer;
843 static const int info_size = sizeof(*info) - sizeof(info->Data);
845 TRACE("(0x%x,%s,%p,%p,%p,%p=%ld)\n",
846 hkey, debugstr_a(name), reserved, type, data, count, count ? *count : 0 );
848 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
850 RtlInitAnsiString( &nameA, name );
851 if ((status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
853 return RtlNtStatusToDosError(status);
855 status = NtQueryValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString,
856 KeyValuePartialInformation, buffer, sizeof(buffer), &total_size );
857 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
859 /* we need to fetch the contents for a string type even if not requested,
860 * because we need to compute the length of the ASCII string. */
861 if (data || is_string(info->Type))
863 /* retry with a dynamically allocated buffer */
864 while (status == STATUS_BUFFER_OVERFLOW)
866 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
867 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
869 status = STATUS_NO_MEMORY;
872 info = (KEY_VALUE_PARTIAL_INFORMATION *)buf_ptr;
873 status = NtQueryValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString,
874 KeyValuePartialInformation, buf_ptr, total_size, &total_size );
877 if (status) goto done;
879 if (is_string(info->Type))
881 DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
882 (total_size - info_size) /sizeof(WCHAR),
883 NULL, 0, NULL, NULL );
886 if (len > *count) status = STATUS_BUFFER_OVERFLOW;
889 WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info_size),
890 (total_size - info_size) /sizeof(WCHAR),
891 data, len, NULL, NULL );
892 /* if the type is REG_SZ and data is not 0-terminated
893 * and there is enough space in the buffer NT appends a \0 */
894 if (len < *count && data[len-1]) data[len] = 0;
897 total_size = len + info_size;
901 if (total_size - info_size > *count) status = STATUS_BUFFER_OVERFLOW;
902 else memcpy( data, buf_ptr + info_size, total_size - info_size );
905 else status = STATUS_SUCCESS;
907 if (type) *type = info->Type;
908 if (count) *count = total_size - info_size;
911 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
912 return RtlNtStatusToDosError(status);
916 /******************************************************************************
917 * RegQueryValueW [ADVAPI32.@]
919 DWORD WINAPI RegQueryValueW( HKEY hkey, LPCWSTR name, LPWSTR data, LPLONG count )
924 TRACE("(%x,%s,%p,%ld)\n", hkey, debugstr_w(name), data, count ? *count : 0 );
928 if ((ret = RegOpenKeyW( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
930 ret = RegQueryValueExW( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
931 if (subkey != hkey) RegCloseKey( subkey );
932 if (ret == ERROR_FILE_NOT_FOUND)
934 /* return empty string if default value not found */
936 if (count) *count = 1;
943 /******************************************************************************
944 * RegQueryValueA [ADVAPI32.@]
946 DWORD WINAPI RegQueryValueA( HKEY hkey, LPCSTR name, LPSTR data, LPLONG count )
951 TRACE("(%x,%s,%p,%ld)\n", hkey, debugstr_a(name), data, count ? *count : 0 );
955 if ((ret = RegOpenKeyA( hkey, name, &subkey )) != ERROR_SUCCESS) return ret;
957 ret = RegQueryValueExA( subkey, NULL, NULL, NULL, (LPBYTE)data, count );
958 if (subkey != hkey) RegCloseKey( subkey );
959 if (ret == ERROR_FILE_NOT_FOUND)
961 /* return empty string if default value not found */
963 if (count) *count = 1;
970 /******************************************************************************
971 * RegEnumValueW [ADVAPI32.@]
974 * hkey [I] Handle to key to query
975 * index [I] Index of value to query
976 * value [O] Value string
977 * val_count [I/O] Size of value buffer (in wchars)
978 * reserved [I] Reserved
980 * data [O] Value data
981 * count [I/O] Size of data buffer (in bytes)
984 DWORD WINAPI RegEnumValueW( HKEY hkey, DWORD index, LPWSTR value, LPDWORD val_count,
985 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
989 char buffer[256], *buf_ptr = buffer;
990 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
991 static const int info_size = sizeof(*info) - sizeof(info->Name);
993 TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
994 hkey, index, value, val_count, reserved, type, data, count );
996 /* NT only checks count, not val_count */
997 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
999 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
1000 if (data) total_size += *count;
1001 total_size = min( sizeof(buffer), total_size );
1003 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1004 buffer, total_size, &total_size );
1005 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
1009 /* retry with a dynamically allocated buffer */
1010 while (status == STATUS_BUFFER_OVERFLOW)
1012 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1013 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
1014 return ERROR_NOT_ENOUGH_MEMORY;
1015 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
1016 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1017 buf_ptr, total_size, &total_size );
1020 if (status) goto done;
1024 if (info->NameLength/sizeof(WCHAR) >= *val_count)
1026 status = STATUS_BUFFER_OVERFLOW;
1029 memcpy( value, info->Name, info->NameLength );
1030 *val_count = info->NameLength / sizeof(WCHAR);
1031 value[*val_count] = 0;
1036 if (total_size - info->DataOffset > *count)
1038 status = STATUS_BUFFER_OVERFLOW;
1041 memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
1042 if (total_size - info->DataOffset <= *count-sizeof(WCHAR) && is_string(info->Type))
1044 /* if the type is REG_SZ and data is not 0-terminated
1045 * and there is enough space in the buffer NT appends a \0 */
1046 WCHAR *ptr = (WCHAR *)(data + total_size - info->DataOffset);
1047 if (ptr > (WCHAR *)data && ptr[-1]) *ptr = 0;
1051 else status = STATUS_SUCCESS;
1053 if (type) *type = info->Type;
1054 if (count) *count = info->DataLength;
1057 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1058 return RtlNtStatusToDosError(status);
1062 /******************************************************************************
1063 * RegEnumValueA [ADVAPI32.@]
1065 DWORD WINAPI RegEnumValueA( HKEY hkey, DWORD index, LPSTR value, LPDWORD val_count,
1066 LPDWORD reserved, LPDWORD type, LPBYTE data, LPDWORD count )
1070 char buffer[256], *buf_ptr = buffer;
1071 KEY_VALUE_FULL_INFORMATION *info = (KEY_VALUE_FULL_INFORMATION *)buffer;
1072 static const int info_size = sizeof(*info) - sizeof(info->Name);
1074 TRACE("(%x,%ld,%p,%p,%p,%p,%p,%p)\n",
1075 hkey, index, value, val_count, reserved, type, data, count );
1077 /* NT only checks count, not val_count */
1078 if ((data && !count) || reserved) return ERROR_INVALID_PARAMETER;
1080 total_size = info_size + (MAX_PATH + 1) * sizeof(WCHAR);
1081 if (data) total_size += *count;
1082 total_size = min( sizeof(buffer), total_size );
1084 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1085 buffer, total_size, &total_size );
1086 if (status && status != STATUS_BUFFER_OVERFLOW) goto done;
1088 /* we need to fetch the contents for a string type even if not requested,
1089 * because we need to compute the length of the ASCII string. */
1090 if (value || data || is_string(info->Type))
1092 /* retry with a dynamically allocated buffer */
1093 while (status == STATUS_BUFFER_OVERFLOW)
1095 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1096 if (!(buf_ptr = HeapAlloc( GetProcessHeap(), 0, total_size )))
1097 return ERROR_NOT_ENOUGH_MEMORY;
1098 info = (KEY_VALUE_FULL_INFORMATION *)buf_ptr;
1099 status = NtEnumerateValueKey( hkey, index, KeyValueFullInformation,
1100 buf_ptr, total_size, &total_size );
1103 if (status) goto done;
1107 DWORD len = WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
1108 NULL, 0, NULL, NULL );
1109 if (len >= *val_count)
1111 status = STATUS_BUFFER_OVERFLOW;
1114 WideCharToMultiByte( CP_ACP, 0, info->Name, info->NameLength/sizeof(WCHAR),
1115 value, len, NULL, NULL );
1120 if (is_string(info->Type))
1122 DWORD len = WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
1123 (total_size - info->DataOffset) / sizeof(WCHAR),
1124 NULL, 0, NULL, NULL );
1129 status = STATUS_BUFFER_OVERFLOW;
1132 WideCharToMultiByte( CP_ACP, 0, (WCHAR *)(buf_ptr + info->DataOffset),
1133 (total_size - info->DataOffset) / sizeof(WCHAR),
1134 data, len, NULL, NULL );
1135 /* if the type is REG_SZ and data is not 0-terminated
1136 * and there is enough space in the buffer NT appends a \0 */
1137 if (len < *count && data[len-1]) data[len] = 0;
1139 info->DataLength = len;
1143 if (total_size - info->DataOffset > *count) status = STATUS_BUFFER_OVERFLOW;
1144 else memcpy( data, buf_ptr + info->DataOffset, total_size - info->DataOffset );
1147 else status = STATUS_SUCCESS;
1149 if (type) *type = info->Type;
1150 if (count) *count = info->DataLength;
1153 if (buf_ptr != buffer) HeapFree( GetProcessHeap(), 0, buf_ptr );
1154 return RtlNtStatusToDosError(status);
1159 /******************************************************************************
1160 * RegDeleteValueW [ADVAPI32.@]
1163 * hkey [I] handle to key
1164 * name [I] name of value to delete
1169 DWORD WINAPI RegDeleteValueW( HKEY hkey, LPCWSTR name )
1171 UNICODE_STRING nameW;
1172 RtlInitUnicodeString( &nameW, name );
1173 return RtlNtStatusToDosError( NtDeleteValueKey( hkey, &nameW ) );
1177 /******************************************************************************
1178 * RegDeleteValueA [ADVAPI32.@]
1180 DWORD WINAPI RegDeleteValueA( HKEY hkey, LPCSTR name )
1185 RtlInitAnsiString( &nameA, name );
1186 if (!(status = RtlAnsiStringToUnicodeString( &NtCurrentTeb()->StaticUnicodeString,
1189 status = NtDeleteValueKey( hkey, &NtCurrentTeb()->StaticUnicodeString );
1191 return RtlNtStatusToDosError( status );
1195 /******************************************************************************
1196 * RegLoadKeyW [ADVAPI32.@]
1199 * hkey [I] Handle of open key
1200 * subkey [I] Address of name of subkey
1201 * filename [I] Address of filename for registry information
1203 LONG WINAPI RegLoadKeyW( HKEY hkey, LPCWSTR subkey, LPCWSTR filename )
1206 DWORD ret, len, err = GetLastError();
1208 TRACE( "(%x,%s,%s)\n", hkey, debugstr_w(subkey), debugstr_w(filename) );
1210 if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
1211 if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
1213 len = strlenW( subkey ) * sizeof(WCHAR);
1214 if (len > MAX_PATH*sizeof(WCHAR)) return ERROR_INVALID_PARAMETER;
1216 if ((file = CreateFileW( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1217 FILE_ATTRIBUTE_NORMAL, 0 )) == INVALID_HANDLE_VALUE)
1219 ret = GetLastError();
1223 SERVER_START_VAR_REQ( load_registry, len )
1227 memcpy( server_data_ptr(req), subkey, len );
1228 ret = RtlNtStatusToDosError( SERVER_CALL() );
1231 CloseHandle( file );
1234 SetLastError( err ); /* restore the last error code */
1239 /******************************************************************************
1240 * RegLoadKeyA [ADVAPI32.@]
1242 LONG WINAPI RegLoadKeyA( HKEY hkey, LPCSTR subkey, LPCSTR filename )
1245 DWORD ret, len, err = GetLastError();
1247 TRACE( "(%x,%s,%s)\n", hkey, debugstr_a(subkey), debugstr_a(filename) );
1249 if (!filename || !*filename) return ERROR_INVALID_PARAMETER;
1250 if (!subkey || !*subkey) return ERROR_INVALID_PARAMETER;
1252 len = MultiByteToWideChar( CP_ACP, 0, subkey, strlen(subkey), NULL, 0 ) * sizeof(WCHAR);
1253 if (len > MAX_PATH*sizeof(WCHAR)) return ERROR_INVALID_PARAMETER;
1255 if ((file = CreateFileA( filename, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1256 FILE_ATTRIBUTE_NORMAL, 0 )) == INVALID_HANDLE_VALUE)
1258 ret = GetLastError();
1262 SERVER_START_VAR_REQ( load_registry, len )
1266 MultiByteToWideChar( CP_ACP, 0, subkey, strlen(subkey),
1267 server_data_ptr(req), len/sizeof(WCHAR) );
1268 ret = RtlNtStatusToDosError( SERVER_CALL() );
1271 CloseHandle( file );
1274 SetLastError( err ); /* restore the last error code */
1279 /******************************************************************************
1280 * RegSaveKeyA [ADVAPI32.@]
1283 * hkey [I] Handle of key where save begins
1284 * lpFile [I] Address of filename to save to
1285 * sa [I] Address of security structure
1287 LONG WINAPI RegSaveKeyA( HKEY hkey, LPCSTR file, LPSECURITY_ATTRIBUTES sa )
1295 TRACE( "(%x,%s,%p)\n", hkey, debugstr_a(file), sa );
1297 if (!file || !*file) return ERROR_INVALID_PARAMETER;
1299 err = GetLastError();
1300 GetFullPathNameA( file, sizeof(buffer), buffer, &name );
1303 sprintf( name, "reg%04x.tmp", count++ );
1304 handle = CreateFileA( buffer, GENERIC_WRITE, 0, NULL,
1305 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1306 if (handle != INVALID_HANDLE_VALUE) break;
1307 if ((ret = GetLastError()) != ERROR_ALREADY_EXISTS) goto done;
1309 /* Something gone haywire ? Please report if this happens abnormally */
1311 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);
1314 SERVER_START_REQ( save_registry )
1318 ret = RtlNtStatusToDosError( SERVER_CALL() );
1322 CloseHandle( handle );
1325 if (!MoveFileExA( buffer, file, MOVEFILE_REPLACE_EXISTING ))
1327 ERR( "Failed to move %s to %s\n", buffer, file );
1328 ret = GetLastError();
1331 if (ret) DeleteFileA( buffer );
1334 SetLastError( err ); /* restore last error code */
1339 /******************************************************************************
1340 * RegSaveKeyW [ADVAPI32.@]
1342 LONG WINAPI RegSaveKeyW( HKEY hkey, LPCWSTR file, LPSECURITY_ATTRIBUTES sa )
1344 LPSTR fileA = HEAP_strdupWtoA( GetProcessHeap(), 0, file );
1345 DWORD ret = RegSaveKeyA( hkey, fileA, sa );
1346 if (fileA) HeapFree( GetProcessHeap(), 0, fileA );
1351 /******************************************************************************
1352 * RegRestoreKeyW [ADVAPI32.@]
1355 * hkey [I] Handle of key where restore begins
1356 * lpFile [I] Address of filename containing saved tree
1357 * dwFlags [I] Optional flags
1359 LONG WINAPI RegRestoreKeyW( HKEY hkey, LPCWSTR lpFile, DWORD dwFlags )
1361 TRACE("(%x,%s,%ld)\n",hkey,debugstr_w(lpFile),dwFlags);
1363 /* It seems to do this check before the hkey check */
1364 if (!lpFile || !*lpFile)
1365 return ERROR_INVALID_PARAMETER;
1367 FIXME("(%x,%s,%ld): stub\n",hkey,debugstr_w(lpFile),dwFlags);
1369 /* Check for file existence */
1371 return ERROR_SUCCESS;
1375 /******************************************************************************
1376 * RegRestoreKeyA [ADVAPI32.@]
1378 LONG WINAPI RegRestoreKeyA( HKEY hkey, LPCSTR lpFile, DWORD dwFlags )
1380 LPWSTR lpFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpFile );
1381 LONG ret = RegRestoreKeyW( hkey, lpFileW, dwFlags );
1382 HeapFree( GetProcessHeap(), 0, lpFileW );
1387 /******************************************************************************
1388 * RegUnLoadKeyW [ADVAPI32.@]
1391 * hkey [I] Handle of open key
1392 * lpSubKey [I] Address of name of subkey to unload
1394 LONG WINAPI RegUnLoadKeyW( HKEY hkey, LPCWSTR lpSubKey )
1396 FIXME("(%x,%s): stub\n",hkey, debugstr_w(lpSubKey));
1397 return ERROR_SUCCESS;
1401 /******************************************************************************
1402 * RegUnLoadKeyA [ADVAPI32.@]
1404 LONG WINAPI RegUnLoadKeyA( HKEY hkey, LPCSTR lpSubKey )
1406 LPWSTR lpSubKeyW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpSubKey );
1407 LONG ret = RegUnLoadKeyW( hkey, lpSubKeyW );
1408 if(lpSubKeyW) HeapFree( GetProcessHeap(), 0, lpSubKeyW);
1413 /******************************************************************************
1414 * RegReplaceKeyW [ADVAPI32.@]
1417 * hkey [I] Handle of open key
1418 * lpSubKey [I] Address of name of subkey
1419 * lpNewFile [I] Address of filename for file with new data
1420 * lpOldFile [I] Address of filename for backup file
1422 LONG WINAPI RegReplaceKeyW( HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpNewFile,
1425 FIXME("(%x,%s,%s,%s): stub\n", hkey, debugstr_w(lpSubKey),
1426 debugstr_w(lpNewFile),debugstr_w(lpOldFile));
1427 return ERROR_SUCCESS;
1431 /******************************************************************************
1432 * RegReplaceKeyA [ADVAPI32.@]
1434 LONG WINAPI RegReplaceKeyA( HKEY hkey, LPCSTR lpSubKey, LPCSTR lpNewFile,
1437 LPWSTR lpSubKeyW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpSubKey );
1438 LPWSTR lpNewFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpNewFile );
1439 LPWSTR lpOldFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpOldFile );
1440 LONG ret = RegReplaceKeyW( hkey, lpSubKeyW, lpNewFileW, lpOldFileW );
1441 HeapFree( GetProcessHeap(), 0, lpOldFileW );
1442 HeapFree( GetProcessHeap(), 0, lpNewFileW );
1443 HeapFree( GetProcessHeap(), 0, lpSubKeyW );
1448 /******************************************************************************
1449 * RegSetKeySecurity [ADVAPI32.@]
1452 * hkey [I] Open handle of key to set
1453 * SecurityInfo [I] Descriptor contents
1454 * pSecurityDesc [I] Address of descriptor for key
1456 LONG WINAPI RegSetKeySecurity( HKEY hkey, SECURITY_INFORMATION SecurityInfo,
1457 PSECURITY_DESCRIPTOR pSecurityDesc )
1459 TRACE("(%x,%ld,%p)\n",hkey,SecurityInfo,pSecurityDesc);
1461 /* It seems to perform this check before the hkey check */
1462 if ((SecurityInfo & OWNER_SECURITY_INFORMATION) ||
1463 (SecurityInfo & GROUP_SECURITY_INFORMATION) ||
1464 (SecurityInfo & DACL_SECURITY_INFORMATION) ||
1465 (SecurityInfo & SACL_SECURITY_INFORMATION)) {
1468 return ERROR_INVALID_PARAMETER;
1471 return ERROR_INVALID_PARAMETER;
1473 FIXME(":(%x,%ld,%p): stub\n",hkey,SecurityInfo,pSecurityDesc);
1475 return ERROR_SUCCESS;
1479 /******************************************************************************
1480 * RegGetKeySecurity [ADVAPI32.@]
1481 * Retrieves a copy of security descriptor protecting the registry key
1484 * hkey [I] Open handle of key to set
1485 * SecurityInformation [I] Descriptor contents
1486 * pSecurityDescriptor [O] Address of descriptor for key
1487 * lpcbSecurityDescriptor [I/O] Address of size of buffer and description
1490 * Success: ERROR_SUCCESS
1491 * Failure: Error code
1493 LONG WINAPI RegGetKeySecurity( HKEY hkey, SECURITY_INFORMATION SecurityInformation,
1494 PSECURITY_DESCRIPTOR pSecurityDescriptor,
1495 LPDWORD lpcbSecurityDescriptor )
1497 TRACE("(%x,%ld,%p,%ld)\n",hkey,SecurityInformation,pSecurityDescriptor,
1498 lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0);
1500 /* FIXME: Check for valid SecurityInformation values */
1502 if (*lpcbSecurityDescriptor < sizeof(SECURITY_DESCRIPTOR))
1503 return ERROR_INSUFFICIENT_BUFFER;
1505 FIXME("(%x,%ld,%p,%ld): stub\n",hkey,SecurityInformation,
1506 pSecurityDescriptor,lpcbSecurityDescriptor?*lpcbSecurityDescriptor:0);
1508 return ERROR_SUCCESS;
1512 /******************************************************************************
1513 * RegFlushKey [ADVAPI32.@]
1514 * Immediately writes key to registry.
1515 * Only returns after data has been written to disk.
1517 * FIXME: does it really wait until data is written ?
1520 * hkey [I] Handle of key to write
1523 * Success: ERROR_SUCCESS
1524 * Failure: Error code
1526 DWORD WINAPI RegFlushKey( HKEY hkey )
1528 FIXME( "(%x): stub\n", hkey );
1529 return ERROR_SUCCESS;
1533 /******************************************************************************
1534 * RegConnectRegistryW [ADVAPI32.@]
1537 * lpMachineName [I] Address of name of remote computer
1538 * hHey [I] Predefined registry handle
1539 * phkResult [I] Address of buffer for remote registry handle
1541 LONG WINAPI RegConnectRegistryW( LPCWSTR lpMachineName, HKEY hKey,
1544 TRACE("(%s,%x,%p): stub\n",debugstr_w(lpMachineName),hKey,phkResult);
1546 if (!lpMachineName || !*lpMachineName) {
1547 /* Use the local machine name */
1548 return RegOpenKeyA( hKey, "", phkResult );
1551 FIXME("Cannot connect to %s\n",debugstr_w(lpMachineName));
1552 return ERROR_BAD_NETPATH;
1556 /******************************************************************************
1557 * RegConnectRegistryA [ADVAPI32.@]
1559 LONG WINAPI RegConnectRegistryA( LPCSTR machine, HKEY hkey, LPHKEY reskey )
1561 LPWSTR machineW = HEAP_strdupAtoW( GetProcessHeap(), 0, machine );
1562 DWORD ret = RegConnectRegistryW( machineW, hkey, reskey );
1563 HeapFree( GetProcessHeap(), 0, machineW );
1568 /******************************************************************************
1569 * RegNotifyChangeKeyValue [ADVAPI32.@]
1572 * hkey [I] Handle of key to watch
1573 * fWatchSubTree [I] Flag for subkey notification
1574 * fdwNotifyFilter [I] Changes to be reported
1575 * hEvent [I] Handle of signaled event
1576 * fAsync [I] Flag for asynchronous reporting
1578 LONG WINAPI RegNotifyChangeKeyValue( HKEY hkey, BOOL fWatchSubTree,
1579 DWORD fdwNotifyFilter, HANDLE hEvent,
1582 FIXME("(%x,%i,%ld,%x,%i): stub\n",hkey,fWatchSubTree,fdwNotifyFilter,
1584 return ERROR_SUCCESS;