I would like to be able to use the standard symbolic names for HRESULTs returned by COM components in my .NET code. For example, I'd like to be able to write code like this:
try {
someComObject->DoSomething();
}
catch (COMException ex) {
if (ex.ErrorCode == E_FAIL) {
HandleFail();
}
else if (ex.ErrorCode == E_OUTOFMEMORY) {
HandleOutOfMemory();
}
else {
HandleComError(ex.ErrorCode);
}
}
However, I can't find anyplace in the .NET frameworks where symbols like E_FAIL, E_OUTOFMEMORY, E_UNEXPECTED, and so on are defined. For native Win32 apps, one can get the definitions from <winerror.h> (see http://msdn.microsoft.com/en-us/library/aa378137(VS.85).aspx).
I can certainly define them myself, wherever I need them, like this:
int E_FAIL = unchecked((int)0x80004005L);
But I would prefer to get the definitions from a standard place, if available. I think I found them defined somewhere once, but my MSDN searches aren't finding them now.
Are there a set of such definitions somewhere in the .NET libraries?