How to compile manifest file with MC.exe?

2.3k views Asked by At

I want to use Windows Event Log in my c# application, so I'm trying to create an Event Provider. I already wrote the xml manifest file, but I've no ideia of how to compile it to generate resource definition file and a C# code file. I know that I have to use the MessageCompiler(MC.exe) and I already have the Windows SDK installed. Can someone give me instructions on how to proceed?

2

There are 2 answers

0
developer On BEST ANSWER

Here is the msdn link for the mc.exe
I did a search and found this document explaining the use of mc.exe for event logging.
Hope that helps.

0
Dai On

(Hello from February 2021!)

  • Microsoft recently changed how mc.exe works.

  • Additionally, the ecmangen.exe ("Manifest Generator") GUI program that's documented in the "Programmers Guide to Eventing" *.docx file (dated 17th December 2010) is no-longer included in the Windows 10 SDK without a replacement.

    • Microsoft's official recommendation is to download the last version of the Windows 10 SDK which included ecmangen.exe... annoyingly MSFT's reply doesn't specify exactly which SDK should be used, referring to it only by the (horribly ambiguous) name "Windows 10 Creators Edition".
      • (It annoys me no-end that they called this "Creators Edition" because it sounds like a separate SKU like Home Edition and Professional Edition)
      • Turns out they're referring to Windows 10 SDK 10.0.15063.468 which you can download from the SDK archive page.
      • It is not included in the Windows 10 SDK for the "Fall Creators Update" (which is version 10.0.16299.91)
  • The minimal install options to get ecmangen.exe is "Windows SDK for Desktop C++ x86 Apps" and "Windows SDK for Desktop C++ amd64 Apps" (you should install both).

  • After you've installed the Windows 10 SDK version 10.0.15063.468, you'll find ecmangen.exe at:

    • "C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x86\ecmangen.exe"
    • "C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64\ecmangen.exe"
      • (yes, the x64 binary is located under the x86 Program Files directory; yes, that's weird).

Now, The documentation in the .NET example of using custom messages says to run the command mc -s EventLogMsgs.mc to build the messages, however this is incorrect.

Instead, do this:

  1. Ensure your manifest file from ecmangen.exe is valid (let's assume it's called "manifest.man").
  2. Open a Visual Studio Developer Command Line prompt window
    • Ever since Windows 7.1 SDK, the SDK no-longer includes its Command Prompt shortcut in the start menu, so do this instead, so temporarily add it to your PATH, like so:
      1. Copy "C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64" to the clipboard (including the double-quotes) - or whatever your actual install-path is.
      2. Open cmd.exe (or PowerShell first, then run cmd)
      3. Type this WITHOUT pressing Enter: SET PATH=%PATH%;
      4. Paste the path from Step 1 (typically this is just a right-click, or the Shift + Insert keystroke).
        • So you have SET PATH=%PATH%;"C:\Program Files (x86)\Windows Kits\10\bin\10.0.15063.0\x64"
      5. And then press Enter
      6. cd %HOMEPATH%
      7. mc.exe -? should now work.
  3. In the same developer command-prompt as Step 2, cd to the directory containing your manifest.man and messages.mc files.
  4. And then run mc.exe messages.mc and it should just work
    • You should now see manifest.h and manifest.rc (and some .bin and TEMP.bin files too...) output into the same directory.