VC自帶的 mc.exe的使用

今天看了《用 C++ 創建簡單的 Win32 服務程序》一文,裏面提到了將服務的運行的狀態寫到日誌裏,這時就要自己生成一個消息表,將這些消息放到程序裏,用ReportEvent就能將記錄寫到日誌裏,文章裏給出了具體方法,但是其中有個步驟是:

用VC自帶的MC.exe 編譯一個*.mc文件,生成*.h,*.rc,*.bin
查了下資料後自己成功編譯了一個.mc文件,具體操作如下:
1、創建.mc文件
.mc的格式是這樣的:

MessageId=100
SymbolicName=EVMSG_INSTALLED
Language=English
The %1 service was installed.
.
MessageId=
SymbolicName=EVMSG_REMOVED
Language=English
The %1 service was removed.
.
MessageId=
SymbolicName=EVMSG_NOTREMOVED
Language=English
The %1 service could not be removed.
.
MessageId=
SymbolicName=EVMSG_CTRLHANDLERNOTINSTALLED
Language=English
The control handler could not be installed.
.
MessageId=
SymbolicName=EVMSG_FAILEDINIT
Language=English
The initialization process failed.
.
MessageId=
SymbolicName=EVMSG_STARTED
Language=English
The service was started.
.
MessageId=
SymbolicName=EVMSG_BADREQUEST
Language=English
The service received an unsupported request.
.
MessageId=
SymbolicName=EVMSG_DEBUG
Language=English
Debug: %1
.
MessageId=
SymbolicName=EVMSG_STOPPED
Language=English
The service was stopped.
.
2 、瞭解mc.exe的命令
先看下下面的描述:
Using MC (The MC Command Line)
The message compiler has the following command-line syntax.
MC [-v] [-w] [-s] [-d] [-h dir] [-e extension] [-r dir] filename[.mc]

-v
Generates verbose output to stderr.
-w
Generates a warning message whenever an insert escape sequence is seen that is a superset of the type supported by the OS/2 MKMSGF utility. These are any escape sequences other than %0 and %n. This option is useful for converting MKMSGF message files to MC format.
-s
Adds an extra line to the beginning of each message that is the symbolic name associated with the message identifier.
-d
Outputs Severity and Facility constants in decimal. Sets the initial output radix for messages to decimal.
-hdirs
Target directory of the generated include file. The include-file name is the base name of the .mc file with a .h extension.
-eextension
Extension for the header file, which can be from one to three characters. The default is .h.
-rdir
Target directory of the generated resource compiler script (.rc file). The script file name is the base name of the .mc file with a .rc extension.
filename[.MC]
Input message file that is compiled into one or more binary resource files, one for each language specified in the message file.
The message compiler reads the message file and generates a C/C++ include file containing definitions for the symbolic names. For each LanguageId statement, the message compiler generates a binary file containing a message table resource. It also generates a single resource script file that contains the appropriate resource compiler statements to include each binary output file as a resource with the appropriate symbolic name and language type.
最後根據這個說明我們知道應該用-v, -h,-r 這幾個命令。
3、編譯
我的編譯步驟 “開始”-“運行” - 'cmd',在命令行下輸入mc -v -h c:\test -r c:\test c:\test\test.mc
前提是你在c:\test目錄下有個編輯好的test.mc 文件,編譯後到c:\test目錄下看看,具體每個命令的含義應該就一目瞭然了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章