Janitorial dlls/advapi32/registry.c W->A cleanup
Tony Lambregts
tony_lambregts at telusplanet.net
Thu Mar 6 08:52:59 CST 2003
Dmitry Timoshkov wrote:
>"Tony Lambregts" <tony_lambregts at telusplanet.net> wrote:
>
>
>
>>-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 );
>>+ UNICODE_STRING fileW;
>>+ LONG ret;
>>+
>>+ RtlCreateUnicodeStringFromAsciiz( &fileW, file );
>>+ ret = RegSaveKeyW( hkey, fileW.Buffer, sa );
>>+ RtlFreeUnicodeString( &fileW );
>> return ret;
>>
>>
>
>In the vast majority of cases where an API takes file name, ANSI version
>of the API is supposed to have a limitation of MAX_PATH characters for
>the name.
>
>Thus, there is no need to waste CPU cycles by allocating/deallocating
>memory, but instead having an automatic buffer on the stack will be
>quite enough. See files/drive.c,GetCurrentDirectoryA for a sample.
>
>All other APIs which get a file name as a parameter should be rewritten
>that way too. Probably that's the task for yet another janitorial project...
>
>All the said above doesn't mean that your patch can't applied as is,
>that just means that there is a better way of doing this task.
>
>
>
Yeah I actually had it that way at one point due to my familairity with
drive.c and well... I ran into some compiler errors (in RegSaveKeyW)
that ended up making the problem worse. Perhaps it was something I
simple I missed. I can take another look at it if it will save some CPU
cycles.
Actually I was more concerned about this section
if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
err = GetLastError();
- GetFullPathNameA( file, sizeof(buffer), buffer, &name );
+ GetFullPathNameW( file, sizeof(buffer), buffer, &nameW );
+ len = WideCharToMultiByte(CP_ACP, 0, nameW, -1, NULL, 0, NULL, NULL);
+ nameA = HeapAlloc(GetProcessHeap(), 0, len);
+ WideCharToMultiByte(CP_ACP, 0, nameW, -1, nameA, len, NULL, NULL);
+
for (;;)
{
- sprintf( name, "reg%04x.tmp", count++ );
- handle = CreateFileA( buffer, GENERIC_WRITE, 0, NULL,
+ sprintf( nameA, "reg%04x.tmp", 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;
I could not use swprintf here. At least not without msvcrt <grin> So I
resorted to converting to ASCII<frown>
--
Tony Lambregts
More information about the wine-devel
mailing list