Creating your own HRESULT?

浪尽此生 提交于 2019-11-29 03:23:27

Yes of course. Typically you create a .mc file and include that in your project. Instruct the mc compiler to build it - this creates a header file and a .rc file. The HRESULTS are defined in the header file. You include the .rc file in your project as normal for the resource compiler to compile - this puts the message definitions into your final module. Then you can use the normal FormatMessage functions to format the messages using the HRESULTS and generate error info and the other stuff.

I have this as the command line for one of my .mc files:

mc   -h "../include" -r "../include" "..\include\errors.mc"

This creates errors.rc and errors.h in the include directory. Then I did:

#include "errors.rc"

in my main .rc file for the project.

The .mc file looks a bit like this:

LanguageNames=(English=0x409:MSG00409)

MessageId=0x1
SymbolicName=SOME_CATEGORY
Language=English
Some Category
.

MessageID=
Severity=Error
SymbolicName=ERROR_INVALID_PROP_INDEX

Language=English
Invalid property index %1
.

with lots of error numbers defined.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!