From 4550b8b7cfb5cbfc3f669e5111697ad3c5bd2131 Mon Sep 17 00:00:00 2001 From: Tony Lambregts Date: Fri, 14 Mar 2003 04:50:34 +0000 Subject: [PATCH] Janitorial. Get rid of W->A calls. --- dlls/advapi32/Makefile.in | 1 + dlls/advapi32/registry.c | 46 +++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/dlls/advapi32/Makefile.in b/dlls/advapi32/Makefile.in index 04fba43f9ad..aa853b78fca 100644 --- a/dlls/advapi32/Makefile.in +++ b/dlls/advapi32/Makefile.in @@ -5,6 +5,7 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = advapi32.dll IMPORTS = kernel32 ntdll +EXTRALIBS = $(LIBUNICODE) LDDLLFLAGS = @LDDLLFLAGS@ SYMBOLFILE = $(MODULE).tmp.o diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c index 9d71c9c91e0..58e5f5230e5 100644 --- a/dlls/advapi32/registry.c +++ b/dlls/advapi32/registry.c @@ -1536,39 +1536,42 @@ LONG WINAPI RegLoadKeyA( HKEY hkey, LPCSTR subkey, LPCSTR filename ) /****************************************************************************** - * RegSaveKeyA [ADVAPI32.@] + * RegSaveKeyW [ADVAPI32.@] * * PARAMS * hkey [I] Handle of key where save begins * lpFile [I] Address of filename to save to * sa [I] Address of security structure */ -LONG WINAPI RegSaveKeyA( HKEY hkey, LPCSTR file, LPSECURITY_ATTRIBUTES sa ) +LONG WINAPI RegSaveKeyW( HKEY hkey, LPCWSTR file, LPSECURITY_ATTRIBUTES sa ) { - char buffer[1024]; + static const WCHAR format[] = + {'r','e','g','%','0','4','x','.','t','m','p',0}; + WCHAR buffer[MAX_PATH]; int count = 0; - LPSTR name; + LPWSTR nameW; DWORD ret, err; HANDLE handle; - TRACE( "(%p,%s,%p)\n", hkey, debugstr_a(file), sa ); + TRACE( "(%p,%s,%p)\n", hkey, debugstr_w(file), sa ); if (!file || !*file) return ERROR_INVALID_PARAMETER; if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE; err = GetLastError(); - GetFullPathNameA( file, sizeof(buffer), buffer, &name ); + GetFullPathNameW( file, sizeof(buffer)/sizeof(WCHAR), buffer, &nameW ); + for (;;) { - sprintf( name, "reg%04x.tmp", count++ ); - handle = CreateFileA( buffer, GENERIC_WRITE, 0, NULL, + snprintfW( nameW, 16, format, count++ ); + handle = CreateFileW( buffer, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 ); if (handle != INVALID_HANDLE_VALUE) break; if ((ret = GetLastError()) != ERROR_ALREADY_EXISTS) goto done; /* Something gone haywire ? Please report if this happens abnormally */ if (count >= 100) - 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); + 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", debugstr_w(buffer), count); } SERVER_START_REQ( save_registry ) @@ -1582,13 +1585,14 @@ LONG WINAPI RegSaveKeyA( HKEY hkey, LPCSTR file, LPSECURITY_ATTRIBUTES sa ) CloseHandle( handle ); if (!ret) { - if (!MoveFileExA( buffer, file, MOVEFILE_REPLACE_EXISTING )) + if (!MoveFileExW( buffer, file, MOVEFILE_REPLACE_EXISTING )) { - ERR( "Failed to move %s to %s\n", buffer, file ); + ERR( "Failed to move %s to %s\n", debugstr_w(buffer), + debugstr_w(file) ); ret = GetLastError(); } } - if (ret) DeleteFileA( buffer ); + if (ret) DeleteFileW( buffer ); done: SetLastError( err ); /* restore last error code */ @@ -1597,14 +1601,18 @@ done: /****************************************************************************** - * RegSaveKeyW [ADVAPI32.@] + * RegSaveKeyA [ADVAPI32.@] */ -LONG WINAPI RegSaveKeyW( HKEY hkey, LPCWSTR file, LPSECURITY_ATTRIBUTES sa ) +LONG WINAPI RegSaveKeyA( HKEY hkey, LPCSTR file, LPSECURITY_ATTRIBUTES sa ) { - LPSTR fileA = HEAP_strdupWtoA( GetProcessHeap(), 0, file ); - DWORD ret = RegSaveKeyA( hkey, fileA, sa ); - if (fileA) HeapFree( GetProcessHeap(), 0, fileA ); - return ret; + UNICODE_STRING *fileW = &NtCurrentTeb()->StaticUnicodeString; + NTSTATUS status; + STRING fileA; + + RtlInitAnsiString(&fileA, file); + if ((status = RtlAnsiStringToUnicodeString(fileW, &fileA, FALSE))) + return RtlNtStatusToDosError( status ); + return RegSaveKeyW(hkey, fileW->Buffer, sa); } @@ -1819,7 +1827,7 @@ LONG WINAPI RegConnectRegistryW( LPCWSTR lpMachineName, HKEY hKey, if (!lpMachineName || !*lpMachineName) { /* Use the local machine name */ - return RegOpenKeyA( hKey, "", phkResult ); + return RegOpenKeyW( hKey, NULL, phkResult ); } FIXME("Cannot connect to %s\n",debugstr_w(lpMachineName));