是否.NET确定共同HRESULT值? [英] Does .NET define common HRESULT values?

查看:155
本文介绍了是否.NET确定共同HRESULT值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建在C#中的COM类,这将是从非托管C ++调用。我想用 ThrowExceptionForHR 但我宁愿不必硬code HRESULT数值。

I'm creating a COM class in C#, which will be called from unmanaged C++. I want to use ThrowExceptionForHR but I'd rather not have to hard-code HRESULT numeric values.

我期待会有共同的HRESULT值的净一些枚举的地方?

I was expecting there would be some enum of common HRESULT values in .Net somewhere?

换句话说,我在哪里可以找到一个名为符号,它映射到HRESULT值传递到 ThrowExceptionForHR

Put another way, where can I find named symbols which map to HRESULT values to pass into ThrowExceptionForHR?

更新:

MS谈话: HRESULT在托管code相关信息。他们引用VSConstants类 Microsoft.VisualStudio.VSConstants 但是当我尝试使用它,它声称该命名空间不存在。

MS talk about it in this page: HRESULT Information in Managed Code. They reference VSConstants class Microsoft.VisualStudio.VSConstants but when I try to use this, it claims that namespace doesn't exist.

推荐答案

是,.NET predefines HRESULT值。您可以使用它们通过的没有的帮助,抛出一个标准的.NET异常只是如果一个管理程序使用的库,你会做的方式。异常的HResult的属性值有时会匹配一个共同的HRESULT值,如果比赛是显而易见的(如OutOfMemoryException异常== 0x800700E),一般一个0x8013xxxx值。

Yes, .NET predefines HRESULT values. You use them by not helping, throw a standard .NET exception just the way you would do it if a managed program uses your library. The exception's HResult property value sometimes matches a common HRESULT value if the match is obvious (like OutOfMemoryException == 0x800700E), in general a 0x8013xxxx value.

在XXXX值被广泛记载和CorError.h SDK头文件中列出。的IErrorInfo :: GetDescription()为您提供了异常的Message属性值。自动的本地化,美观大方。你不能得到神圣的堆栈跟踪。

The xxxx values are widely documented and listed in the CorError.h SDK header file. IErrorInfo::GetDescription() gives you the exception's Message property value. Automagically localized, nice. You can't get the holy stack trace.

这篇关于是否.NET确定共同HRESULT值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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