📜 ⬆️ ⬇️

MC.exe (Message compiler), rc.exe, link.exe to generate .dll for EventMessageFile

Good afternoon, dear readers of Habr. This post is a guide for creating a dynamic .dll library, which contains the messages necessary to display in a custom logger, located in the Windows Event Viewer \ Application and Services Logs \ yyyyu (as an example).



In the custom log, you can often see messages, the description of which contains:


')
This means that the source of the events yyyy does not contain the necessary set of ID and Description.

In order to correct this situation, it is necessary:

1. Open regedit in the following path: HKLM \ SYSTEM \ CurrentControlSet \ Services \ EventLog and make sure that your section exists.

2. Create eventMessage.txt into which you need to place your parameters, an example with msdn , save in the required encoding of Windows-1251 or Unicode and the eventMessage.mc format.

Note: when filling eventMessage with your ID and description, ALWAYS after the description it is necessary to put a period on a new line, and after it transfer the carriage to a new line.

Example:

MessageId=0x1 SymbolicName=CAT_1 Language=English OutDescription for your application . MessageId=0x2 

If you do not take into account this feature, then there may be unforeseen errors at compile time.

3. Run cmd as administrator.

4. Run the command: mc.exe -u C: \ SomeFolder \ eventMessage.mc -r C: \ SomeFolder \ result

Note : mc.exe, in a special case, is located in C:\Program Files (x86)\Windows Kits\10\bin\10.0.16299.0\x86 you can use -A (W-1251 ANSI, ) instead of the -u (Unicode) format, you can use -A (W-1251 ANSI, ) , and the -r parameter is the output location where the files will be saved after compilation.

After the command is executed, the binary file and the eventMessage.rc file in C: \ SomeFolder \ result will be created.

5. Execute the command: rc.exe C: \ SomeFolder \ result \ eventMessage.rc

Note : rc.exe is in the same directory as mc.exe.

After compilation, the eventMessage.res file will be created, which is required to create a dynamic library.

6. Run the command: link.exe -dll -noentry /out:C:\SomeFolder\result\ OurMessageSet.dll C: \ SomeFolder \ result \ eventMessage.res.

Note: link.exe is, in a special case, in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\SDK\ScopeCppSDK\VC\bin

7. Congratulations, we have created a long-awaited library with you, but this is not all. Go to regedit to our directory from step 1. In the directory field, create a string parameter (string value), naming this creation in the EventMessageFile, and in the value indicate the path to our library: C: \ SomeFolder \ result \ OurMessageSet.dll. It looks like this:



Tools reviewed: mc.exe, rc.exe, link.exe.

May the force be with you.

Source: https://habr.com/ru/post/426121/


All Articles