Dmitry Timoshkov wrote:
"Tony Lambregts" tony_lambregts@telusplanet.net wrote:
-IMPORTS = kernel32 ntdll +IMPORTS = kernel32 ntdll user32
I'm not sure Alexandre will like it. Until for now, creation of the circular dependencies were prohibitted. Probably it's better to use swprintf from ntdll,
&*#@ Well. I am very much at the end of my rope here. As I said from the begining I could not find a way to use swprintf. If there is a way it is not obvious. Now I may be thick at times but IMO there should be a way of using swprintf here. So what am I missing.
or a set of calls strcpyW/ntdll._ultow/strcatW.
I would prefer not to use this workaround except as a last resort. At least, I would like some definitive reason why we can't use swprintf.
-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;
- STRING fileA;
- if (!file || !*file)
- {
SetLastError(ERROR_PATH_NOT_FOUND);
return FALSE;
As Alexandre has already pointed out, registry APIs are supposed to not change last error value.
OK.
- }
- RtlInitAnsiString(&fileA, file);
- RtlAnsiStringToUnicodeString(fileW, &fileA, FALSE);
- if (fileW) return RegSaveKeyW(hkey, fileW->Buffer, sa);
- return FALSE;
fileW is always not NULL, so, there is no need to check it. What you really need to check is a return value of RtlAnsiStringToUnicodeString.
so this would be better.
-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; + STRING fileA; + + if (!file || !*file) + { + return FALSE; + } + + RtlInitAnsiString(&fileA, file); + if (!RtlAnsiStringToUnicodeString(fileW, &fileA, FALSE)); + { + return RegSaveKeyW(hkey, fileW->Buffer, sa); + } + return FALSE; + }