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
604 stub BroadcastSystemMessage
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
609 pascal16 SetForegroundWindow(word) SetForegroundWindow16
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 FindWindowEx16(HWND16,HWND16,SEGPTR,LPCSTR);
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);
HWND16 WINAPI GetActiveWindow16(void);
WORD WINAPI GetAsyncKeyState16(INT16);

View file

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