创建自己的HRESULT? [英] Creating your own HRESULT?

查看:199
本文介绍了创建自己的HRESULT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一个项目使用了很多COM和HRESULTS。 ANyways我想知道是否可能定义自己的HRESULT,并能够使用FormatMessage()为我们自己的HRESULT?



我挖了,没有找到任何东西。任何想法?



EDIT



基本上我想定义一组自己的HRESULT,而不是只返回E_FAIL 。或者其他一般的。像E_FAIL是好的。但让我说,我想指出,例如地理处理子系统崩溃或文件是一个无效的光栅图像。应用程序已经使用com。

解决方案

是的。通常,您需要创建 .mc文件和包括在您的项目。指示 mc编译器来构建它 - 这将创建一个头文件和一个.rc文件。 HRESULTS在头文件中定义。您在项目中包含.rc文件作为编译资源编译器的正常操作 - 这将消息定义放入最终模块。然后,您可以使用正常的 FormatMessage 函数使用HRESULTS格式化消息并生成错误信息和其他内容。



我有这个作为我的.mc文件的命令行:

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

这会在include目录中创建errors.rc和errors.h。然后我做了:

  #includeerrors.rc


.mc文件看起来有点像这样:

/ p>

  LanguageNames =(English = 0x409:MSG00409)

MessageId = 0x1
SymbolicName = SOME_CATEGORY
语言=英语
一些类别


MessageID =
严重性=错误
SymbolicName = ERROR_INVALID_PROP_INDEX

语言=英语
无效的属性索引%1

定义了大量错误号。


I already have a project that uses alot of COM, and HRESULTS. ANyways i was wondering if its possible to define your own HRESULT, AND be able to use the FormatMessage() for our own HRESULT?

I dug around and cant find anything. Any ideas?

EDIT

Basically i want to define a set of my own HRESULT's instead of just returning E_FAIL. Or one of the other generic ones. Like E_FAIL is fine. But lets say i want to point out that for example the Geoprocessing subsystem crashed or the file is an invalid Raster Image. The application already uses com through out it.

解决方案

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.

这篇关于创建自己的HRESULT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆