现在的位置: 首页 > 综合 > 正文

VC中加入Message table资源

2013年04月05日 ⁄ 综合 ⁄ 共 1372字 ⁄ 字号 评论关闭
 

查看FormatMessage函数的说明时,发现可以使用非系统错误码,而使用自定义的消息码和消息说明.

搜索google:vc add message table resource 

找到下面文章:

Adding a Message Table "Add new Item" wizard with two clicks

链接为:

http://www.codeproject.com/tools/MsgTableWiz.asp

Introduction

Three days ago I decided to write a class and to insert in it something to simply manage the class generated errors. So I started to write an error class to do that and I wanted this class implement an easy Message Table access to let formatting of error messages, and because of the facility of using this special kind of "string table" with GetLastError, I could use SetLastError with my class. But the problem was... Microsoft development products don't give importance to the message tables and don't implement any kind of easy access to them even if they include the message table compiler (mc.exe) in the tools directory. So I searched MSDN for "mc.exe" and after giving a look at the command line parameters I selected the compiler in the Properties window of my .mc file with the right flags. The message compiler creates a .h and a .rc files, the first containing #define directives for the messages, and the second a resource include of one (one for each language) .bin file containing the message strings. And now? I have to include the .h and .rc files in the project, and insert a #include directive in each file I want to use the message symbols.. oh my, should I do this in every project I want to use Message Tables? Oh no, just make a wizard! :)

按照作者的方法,在MSDN中搜索"mc.exe"找到了例子.先编写一个Message Table的文本,然后用mc命令编译,将得到的.h和.rc文件加入工程资源中即可.

然后FormatMessage使用FORMAT_MESSAGE_FROM_HMODULE标志

抱歉!评论已关闭.