Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does .NET define common HRESULT values? [duplicate]

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.

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

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

Update:

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.

like image 602
Mr. Boy Avatar asked Oct 14 '25 03:10

Mr. Boy


1 Answers

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.

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.

like image 182
Hans Passant Avatar answered Oct 17 '25 16:10

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!