简体   繁体   English

创建自己的HRESULT?

[英]Creating your own HRESULT?

I already have a project that uses alot of COM, and HRESULTS. 我已经有一个项目使用了很多COM和HRESULTS。 ANyways i was wondering if its possible to define your own HRESULT, AND be able to use the FormatMessage() for our own HRESULT? 我想知道是否有可能定义你自己的HRESULT,并且能够将FormatMessage()用于我们自己的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. 基本上我想定义一组我自己的HRESULT,而不是只返回E_FAIL。 Or one of the other generic ones. 或者其他通用的。 Like E_FAIL is fine. 像E_FAIL一样好。 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. 该应用程序已经通过它使用com。

Yes of course. 当然是。 Typically you create a .mc file and include that in your project. 通常,您创建一个.mc文件并将其包含在项目中。 Instruct the mc compiler to build it - this creates a header file and a .rc file. 指示mc编译器构建它 - 这会创建一个头文件和一个.rc文件。 The HRESULTS are defined in the header file. HRESULTS在头文件中定义。 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. 您可以在项目中包含.rc文件,以便编译资源编译器 - 这会将消息定义放入最终模块中。 Then you can use the normal FormatMessage functions to format the messages using the HRESULTS and generate error info and the other stuff. 然后,您可以使用普通的FormatMessage函数使用HRESULTS格式化消息,并生成错误信息和其他内容。

I have this as the command line for one of my .mc files: 我将此作为我的.mc文件的命令行:

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

This creates errors.rc and errors.h in the include directory. 这会在include目录中创建errors.rc和errors.h。 Then I did: 然后我做了:

#include "errors.rc"

in my main .rc file for the project. 在我项目的主.rc文件中。

The .mc file looks a bit like this: .mc文件看起来有点像这样:

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. 定义了大量错误编号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM