partial FormatMessage wine sync

svn path=/trunk/; revision=44194
This commit is contained in:
Christoph von Wittich 2009-11-16 01:37:12 +00:00
parent 0b4a63a920
commit 073d07ac36

View file

@ -75,6 +75,42 @@ __inline static LPSTR HEAP_strdupWtoA( HANDLE heap, DWORD flags, LPCWSTR str )
* Yes, ANSI strings in win32 resources. Go figure.
*/
/**********************************************************************
* load_messageW (internal)
*/
static LPWSTR load_messageW( HMODULE module, UINT id, WORD lang )
{
PRTL_MESSAGE_RESOURCE_ENTRY mre;
WCHAR *buffer;
NTSTATUS Status;
TRACE("module = %p, id = %08x\n", module, id );
if (!module) module = GetModuleHandleW( NULL );
Status = RtlFindMessage( module, (ULONG) RT_MESSAGETABLE, lang, id, &mre );
if (!NT_SUCCESS(Status))
{
SetLastError( RtlNtStatusToDosError(Status) );
return NULL;
}
if (mre->Flags & MESSAGE_RESOURCE_UNICODE)
{
int len = (strlenW( (const WCHAR *)mre->Text ) + 1) * sizeof(WCHAR);
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL;
memcpy( buffer, mre->Text, len );
}
else
{
int len = MultiByteToWideChar( CP_ACP, 0, (const char *)mre->Text, -1, NULL, 0 );
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL;
MultiByteToWideChar( CP_ACP, 0, (const char*)mre->Text, -1, buffer, len );
}
//TRACE("returning %s\n", wine_dbgstr_w(buffer));
return buffer;
}
/**********************************************************************
* load_messageA (internal)
*/
@ -90,7 +126,10 @@ static LPSTR load_messageA( HMODULE module, UINT id, WORD lang )
if (!module) module = GetModuleHandleW( NULL );
Status = RtlFindMessage( module, (ULONG) RT_MESSAGETABLE, lang, id, &mre );
if (!NT_SUCCESS(Status))
{
SetLastError( RtlNtStatusToDosError(Status) );
return NULL;
}
if (mre->Flags & MESSAGE_RESOURCE_UNICODE)
{
@ -109,36 +148,6 @@ static LPSTR load_messageA( HMODULE module, UINT id, WORD lang )
}
static LPWSTR load_messageW( HMODULE module, UINT id, WORD lang )
{
PRTL_MESSAGE_RESOURCE_ENTRY mre;
WCHAR *buffer;
NTSTATUS Status;
TRACE("module = %p, id = %08x\n", module, id );
if (!module) module = GetModuleHandleW( NULL );
Status = RtlFindMessage( module, (ULONG) RT_MESSAGETABLE, lang, id, &mre );
if (!NT_SUCCESS(Status))
return NULL;
if (mre->Flags & MESSAGE_RESOURCE_UNICODE)
{
int len = (strlenW( (const WCHAR *)mre->Text ) + 1) * sizeof(WCHAR);
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len ))) return NULL;
memcpy( buffer, mre->Text, len );
}
else
{
int len = MultiByteToWideChar( CP_ACP, 0, (const char *)mre->Text, -1, NULL, 0 );
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL;
MultiByteToWideChar( CP_ACP, 0, (const char*)mre->Text, -1, buffer, len );
}
//TRACE("returning %s\n", wine_dbgstr_w(buffer));
return buffer;
}
/***********************************************************************
* FormatMessageA (KERNEL32.@)
* FIXME: missing wrap,
@ -199,7 +208,6 @@ DWORD WINAPI FormatMessageA(
if (!from)
{
SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND);
return 0;
}
}
@ -457,7 +465,6 @@ DWORD WINAPI FormatMessageW(
if (!from)
{
SetLastError (ERROR_RESOURCE_LANG_NOT_FOUND);
return 0;
}
}
@ -641,7 +648,7 @@ DWORD WINAPI FormatMessageW(
if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
/* nSize is the MINIMUM size */
DWORD len = strlenW(target) + 1;
*((LPVOID*)lpBuffer) = (LPVOID)LocalAlloc(LMEM_ZEROINIT,len*sizeof(WCHAR));
*((LPVOID*)lpBuffer) = LocalAlloc(LMEM_ZEROINIT,len*sizeof(WCHAR));
strcpyW(*(LPWSTR*)lpBuffer, target);
}
else lstrcpynW(lpBuffer, target, nSize);