Use LoadString16 for FormatMessage16 and handle

FORMAT_MESSAGE_ALLOCATE_BUFFER flag.
This commit is contained in:
Uwe Bonnes 1999-10-13 14:00:09 +00:00 committed by Alexandre Julliard
parent 81bc9dfbaa
commit 22d4b0afdd
3 changed files with 16 additions and 13 deletions

View file

@ -485,7 +485,7 @@ file user.exe
602 stub SetCheckCursorTimer 602 stub SetCheckCursorTimer
604 stub BroadcastSystemMessage 604 stub BroadcastSystemMessage
605 stub HackTaskMonitor 605 stub HackTaskMonitor
606 pascal FormatMessage(long ptr word word ptr word ptr) FormatMessage16 606 pascal16 FormatMessage(long segptr word word ptr word ptr) FormatMessage16
608 pascal16 GetForegroundWindow() GetForegroundWindow16 608 pascal16 GetForegroundWindow() GetForegroundWindow16
609 pascal16 SetForegroundWindow(word) SetForegroundWindow16 609 pascal16 SetForegroundWindow(word) SetForegroundWindow16
610 pascal16 DestroyIcon32(word word) CURSORICON_Destroy 610 pascal16 DestroyIcon32(word word) CURSORICON_Destroy

View file

@ -712,7 +712,7 @@ INT16 WINAPI FillRect16(HDC16,const RECT16*,HBRUSH16);
HWND16 WINAPI FindWindow16(SEGPTR,LPCSTR); HWND16 WINAPI FindWindow16(SEGPTR,LPCSTR);
HWND16 WINAPI FindWindowEx16(HWND16,HWND16,SEGPTR,LPCSTR); HWND16 WINAPI FindWindowEx16(HWND16,HWND16,SEGPTR,LPCSTR);
BOOL16 WINAPI FlashWindow16(HWND16,BOOL16); BOOL16 WINAPI FlashWindow16(HWND16,BOOL16);
DWORD WINAPI FormatMessage16(DWORD,LPCVOID,WORD,WORD,LPSTR,WORD,LPDWORD); DWORD WINAPI FormatMessage16(DWORD,SEGPTR,WORD,WORD,LPSTR,WORD,LPDWORD);
INT16 WINAPI FrameRect16(HDC16,const RECT16*,HBRUSH16); INT16 WINAPI FrameRect16(HDC16,const RECT16*,HBRUSH16);
HWND16 WINAPI GetActiveWindow16(void); HWND16 WINAPI GetActiveWindow16(void);
WORD WINAPI GetAsyncKeyState16(INT16); WORD WINAPI GetAsyncKeyState16(INT16);

View file

@ -489,10 +489,10 @@ BOOL WINAPI IsCharUpperW(WCHAR x)
*/ */
DWORD WINAPI FormatMessage16( DWORD WINAPI FormatMessage16(
DWORD dwFlags, DWORD dwFlags,
LPCVOID lpSource, SEGPTR lpSource, /*not always a valid pointer*/
WORD dwMessageId, WORD dwMessageId,
WORD dwLanguageId, WORD dwLanguageId,
LPSTR lpBuffer, LPSTR lpBuffer, /* *((HLOCAL16*)) for FORMAT_MESSAGE_ALLOCATE_BUFFER*/
WORD nSize, WORD nSize,
LPDWORD args /* va_list *args */ LPDWORD args /* va_list *args */
) { ) {
@ -503,26 +503,28 @@ DWORD WINAPI FormatMessage16(
LPSTR from,f; LPSTR from,f;
DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK; DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK;
DWORD nolinefeed = 0; DWORD nolinefeed = 0;
LPSTR allocstring;
TRACE("(0x%lx,%p,%d,0x%x,%p,%d,%p)\n", TRACE("(0x%lx,%lx,%d,0x%x,%p,%d,%p)\n",
dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args); dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args);
if (width) if (width)
FIXME("line wrapping not supported.\n"); FIXME("line wrapping not supported.\n");
from = NULL; from = NULL;
if (dwFlags & FORMAT_MESSAGE_FROM_STRING) if (dwFlags & FORMAT_MESSAGE_FROM_STRING)
from = HEAP_strdupA( GetProcessHeap(), 0, (LPSTR)lpSource); from = HEAP_strdupA( GetProcessHeap(), 0, PTR_SEG_TO_LIN(lpSource));
if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) { if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) {
from = HeapAlloc( GetProcessHeap(),0,200 ); from = HeapAlloc( GetProcessHeap(),0,200 );
sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId); sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId);
} }
if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) { if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) {
INT bufsize; INT16 bufsize;
HINSTANCE16 hinst16 = ((HMODULE)lpSource & 0xffff);
dwMessageId &= 0xFFFF; dwMessageId &= 0xFFFF;
bufsize=LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,NULL,100); bufsize=LoadString16(hinst16,dwMessageId,NULL,0);
if (bufsize) { if (bufsize) {
from = HeapAlloc( GetProcessHeap(), 0, bufsize + 1 ); from = HeapAlloc( GetProcessHeap(), 0, bufsize +1);
LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,from,bufsize+1); LoadString16(hinst16,dwMessageId,from,bufsize+1);
} }
} }
target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100); target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100);
@ -642,14 +644,15 @@ DWORD WINAPI FormatMessage16(
TRACE("-- %s\n",debugstr_a(target)); TRACE("-- %s\n",debugstr_a(target));
if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) { if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) {
/* nSize is the MINIMUM size */ /* nSize is the MINIMUM size */
*((LPVOID*)lpBuffer) = (LPVOID)LocalAlloc(GMEM_ZEROINIT,talloced); *((HLOCAL16*)lpBuffer)= LocalAlloc16(LPTR,talloced);
memcpy(*(LPSTR*)lpBuffer,target,talloced); allocstring=PTR_SEG_OFF_TO_LIN(CURRENT_DS,*((HLOCAL16*)lpBuffer));
memcpy( allocstring,target,talloced);
} else } else
strncpy(lpBuffer,target,nSize); strncpy(lpBuffer,target,nSize);
HeapFree(GetProcessHeap(),0,target); HeapFree(GetProcessHeap(),0,target);
if (from) HeapFree(GetProcessHeap(),0,from); if (from) HeapFree(GetProcessHeap(),0,from);
return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ? return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ?
strlen(*(LPSTR*)lpBuffer): strlen(allocstring):
strlen(lpBuffer); strlen(lpBuffer);
#else #else
return 0; return 0;