Commit a64603d3 authored by Dave Pickles's avatar Dave Pickles Committed by Alexandre Julliard

Improved FormatMessage:

- Added full support for FORMAT_MESSAGE_FROM_SYSTEM - Implemented language search as documented - Illegal combinations of options trapped. - Message table for system messages added.
parent fc846d70
*.spec.c
Makefile
kernel.s
libkernel32.so.1.0
locale_rc.s
......@@ -7,6 +7,7 @@ SOVERSION = 1.0
ALTNAMES = comm kernel system toolhelp windebug win87em wprocs
C_SRCS = \
format_msg.c \
kernel_main.c \
thunk.c \
utthunk.c \
......@@ -15,8 +16,13 @@ C_SRCS = \
wowthunk.c
RC_SRCS = \
locale_rc.rc
kernel.rc
MC_SRCS = \
messages/winerr_enu.mc
@MAKE_DLL_RULES@
depend: $(MC_SRCS:.mc=.rc)
### Dependencies:
#include "locale_rc.rc"
#include "messages/winerr_enu.rc"
name kernel32
type win32
init MAIN_KernelInit
rsrc locale_rc
rsrc kernel
import ntdll.dll
......
......@@ -967,109 +967,6 @@ INT WINAPI LoadStringA( HINSTANCE instance, UINT resource_id,
return retval;
}
/* Messages...used by FormatMessage32* (KERNEL32.something)
*
* They can be specified either directly or using a message ID and
* loading them from the resource.
*
* The resourcedata has following format:
* start:
* 0: DWORD nrofentries
* nrofentries * subentry:
* 0: DWORD firstentry
* 4: DWORD lastentry
* 8: DWORD offset from start to the stringentries
*
* (lastentry-firstentry) * stringentry:
* 0: WORD len (0 marks end)
* 2: WORD flags
* 4: CHAR[len-4]
* (stringentry i of a subentry refers to the ID 'firstentry+i')
*
* Yes, ANSI strings in win32 resources. Go figure.
*/
/**********************************************************************
* LoadMessageA (internal)
*/
INT WINAPI LoadMessageA( HMODULE instance, UINT id, WORD lang,
LPSTR buffer, INT buflen )
{
HGLOBAL hmem;
HRSRC hrsrc;
PMESSAGE_RESOURCE_DATA mrd;
PMESSAGE_RESOURCE_BLOCK mrb;
PMESSAGE_RESOURCE_ENTRY mre;
int i,slen;
TRACE("instance = %08lx, id = %08lx, buffer = %p, length = %ld\n", (DWORD)instance, (DWORD)id, buffer, (DWORD)buflen);
/*FIXME: I am not sure about the '1' ... But I've only seen those entries*/
hrsrc = FindResourceExW(instance,RT_MESSAGELISTW,(LPWSTR)1,lang);
if (!hrsrc) return 0;
hmem = LoadResource( instance, hrsrc );
if (!hmem) return 0;
mrd = (PMESSAGE_RESOURCE_DATA)LockResource(hmem);
mre = NULL;
mrb = &(mrd->Blocks[0]);
for (i=mrd->NumberOfBlocks;i--;) {
if ((id>=mrb->LowId) && (id<=mrb->HighId)) {
mre = (PMESSAGE_RESOURCE_ENTRY)(((char*)mrd)+mrb->OffsetToEntries);
id -= mrb->LowId;
break;
}
mrb++;
}
if (!mre)
return 0;
for (i=id;i--;) {
if (!mre->Length)
return 0;
mre = (PMESSAGE_RESOURCE_ENTRY)(((char*)mre)+(mre->Length));
}
slen=mre->Length;
TRACE(" - strlen=%d\n",slen);
i = min(buflen - 1, slen);
if (buffer == NULL)
return slen;
if (i>0) {
lstrcpynA(buffer,(char*)mre->Text,i);
buffer[i]=0;
} else {
if (buflen>1) {
buffer[0]=0;
return 0;
}
}
if (buffer)
TRACE("'%s' copied !\n", buffer);
return i;
}
/**********************************************************************
* LoadMessageW (internal)
*/
INT WINAPI LoadMessageW( HMODULE instance, UINT id, WORD lang,
LPWSTR buffer, INT buflen )
{
INT retval;
LPSTR buffer2 = NULL;
if (buffer && buflen)
buffer2 = HeapAlloc( GetProcessHeap(), 0, buflen );
retval = LoadMessageA(instance,id,lang,buffer2,buflen);
if (buffer)
{
if (retval) {
lstrcpynAtoW( buffer, buffer2, buflen );
retval = lstrlenW( buffer );
}
HeapFree( GetProcessHeap(), 0, buffer2 );
}
return retval;
}
/**********************************************************************
* EnumResourceTypesA (KERNEL32.90)
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment