I would like to be able to use the standard symbolic names for HRESULT returned by COM components in my .NET code. For example, I would like to write code as follows:
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 cannot find anywhere in the .NET frameworks where characters such as E_FAIL, E_OUTOFMEMORY, E_UNEXPECTED, etc. are defined. For native Win32 applications, you can get the definitions from <winerror.h> (see http://msdn.microsoft.com/en-us/library/aa378137(VS.85).aspx ).
I can, of course, define them myself, wherever they need, for example:
int E_FAIL = unchecked((int)0x80004005L);
, . , - , MSDN .
- .NET?