Visual C++: [TIP] How to make a "Message DLL"?
Q: How to make a "Message DLL"?
Few more info
Windows system as well as many applications and libraries use message table resources (RT_MESSAGETABLE) in order to store message descriptions (error, warning, information, etc).
Further, FormatMessage can be called to retrieve the detailed description, given a message identifier/code returned by a WinAPI function call, GetLastError, taken from an event log, and so on.
Message table resources can be located in any type of binary file which can contain resources (exe, dll, ocx, etc).
If we want to store our own messages, a convenient place is a resource-only DLL. We can call it "Message DLL".
A: Here is how to make a "Message DLL", step by step (Visual Sudio 20xx):
- Make a new Win32 Project.
http://www.codexpert.ro/forum/download/file.php?id=616
. - In Win32 Application Wizard, check "DLL" and "Empty Project".
http://www.codexpert.ro/forum/download/file.php?id=617
. - Go to Project Property/Linker/Advanced and change No Entry Point property to "Yes(/NOENTRY)".
This is required to create a resource-only DLL.
http://www.codexpert.ro/forum/download/file.php?id=623
. - Add a message text file, let's say it "MyMessages.mc".
http://www.codexpert.ro/forum/download/file.php?id=619
. - Write a minimum of entries in .mc file, e.g. a message category.
Code:
MessageIdTypedef=WORD
MessageId=0x1
SymbolicName=CATEGORY_GENERAL
Language=English
General
.
; /* more entries go here */
- Go to Project Properties/Build Events/Pre-link Event and type the command for message compiler (MC.exe).
http://www.codexpert.ro/forum/download/file.php?id=620
. - Build the solution.
The message compiler generates a binary, a resource script, and a header file (e.g. MSG00001.bin, MyMessages.rc and MyMessages.h).
- In Solution Explorer window, right click on the project name and add MyMessages.rc and MyMessages.h.
http://www.codexpert.ro/forum/download/file.php?id=621
. - Further, complete the .mc file adding categries, messages and so on. The Message Text Files reference and examples can be found in MSDN (see the links below).
Resources [MSDN]
See also