Creating your own HRESULT?(创建自己的 HRESULT?)
问题描述
我已经有一个使用大量 COM 和 HRESULTS 的项目.无论如何,我想知道是否可以定义自己的 HRESULT,并且能够将 FormatMessage() 用于我们自己的 HRESULT?
I already have a project that uses a lot of COM, and HRESULTS. Anyways I was wondering if it's possible to define your own HRESULT, AND be able to use the FormatMessage() for our own HRESULT?
我翻遍了,找不到任何东西.有什么想法吗?
I dug around and can't find anything. Any ideas?
编辑
基本上我想定义一组我自己的 HRESULT,而不是仅仅返回 E_FAIL.或其他通用的之一.像 E_FAIL 就可以了.但假设我想指出,例如地理处理子系统崩溃或文件是无效的光栅图像.该应用程序已经在整个过程中使用了 COM.
Basically I want to define a set of my own HRESULTs instead of just returning E_FAIL. Or one of the other generic ones. Like E_FAIL is fine. But let's 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 throughout it.
推荐答案
当然可以.通常,您会创建一个 .mc 文件并包含在你的项目中.指示 mc 编译器 构建它 - 这个创建一个头文件和一个 .rc 文件.HRESULTS 在头文件中定义.您在项目中包含 .rc 文件,以供资源编译器编译 - 这会将消息定义放入您的最终模块中.然后您可以使用普通的 FormatMessage 函数使用 HRESULTS 格式化消息并生成错误信息和其他内容.
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.
我将此作为我的 .mc 文件之一的命令行:
I have this as the command line for one of my .mc files:
mc -h "../include" -r "../include" "..includeerrors.mc"
这会在包含目录中创建 errors.rc 和 errors.h.然后我做了:
This creates errors.rc and errors.h in the include directory. Then I did:
#include "errors.rc"
在我的项目主 .rc 文件中.
in my main .rc file for the project.
.mc 文件看起来有点像这样:
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
.
定义了很多错误号.
这篇关于创建自己的 HRESULT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:创建自己的 HRESULT?
基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01