September 26, 2022, 05:46:17 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Message Tables

Started by sapero, January 16, 2009, 05:39:55 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sapero

January 16, 2009, 05:39:55 AM Last Edit: January 16, 2009, 05:48:47 AM by sapero
Message tables are special string resources used when displaying error messages. They are declared in a resource file using the MESSAGETABLE resource-definition statement. To access the message strings, use the FormatMessage function.

The system provides a message table for the system error codes. To retrieve the string that corresponds to the error code, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag.

In this example we create a custom message table and use it with the FormatMessage function. To compile the message tabl;e script, you'll need Visual Studio (up to 2005), Platform SDK or MSDN. Find mc.exe and copy it to /system32 or your custom folder addded to the %PATH% envinronment variable.
If you do not find mc.exe, I have uploaded already compiled, binary resource (MSG00409.bin).

Attached is also a bat file which calls the message compiler, and additional h2inc tool which converts the generated C header to aurora or emergence.
h2inc aurora mesagetable.h
h2inc ebasic mesagetable.h


#include "windows.inc"
#include "messagetable.inc"

sub main()
{
dstring szError[256] = "Please compile mesagetable.mc first";
LPSTR pszArguments[2];

// simulate failing NEW
pointer pNew = NULL;//new(int, 5);
if (!pNew)
{
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, _hinstance+0, ERROR_NEW_FAILED, 0, szError, 256, NULL);
MessageBox(0, szError, "Error");
}

// simulate failing AllocHeap
heap pHeap = NULL;//AllocHeap(256);
if (!pHeap)
{
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, _hinstance+0, ERROR_ALLOCHEAP_FAILED, 0, szError, 256, NULL);
MessageBox(0, szError, "Error");
}

// simulate failing function
BOOL success = IsTrue(FALSE);
if (!success)
{
// The pszArguments[0] function failed to pszArguments[1]
pszArguments[0] = "IsTrue";
pszArguments[1] = "accept input parameter";

FormatMessage(FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ARGUMENT_ARRAY,
_hinstance+0, ERROR_MY_FUNCTION_FAILED, 0, szError, 256, &pszArguments);

MessageBox(0, szError, "Error");
}
}


sub IsTrue(BOOL expression),BOOL
{
return expression;
}


More about message tables you can find in your MSDN, in Tools/SDK Tools/Resource Tools/Message Compiler.