What values to return for S_OK or E_FAIL from c# .net code?
E_FAIL is Hex 80004005 in WinError.h
You can see the full Common HRESULT Values. You don't have to install C++ just to see the values.
UPDATE:
The signed and unsigned versions of 0x80004005 are just two representations of the same bit mask. If you're getting a casting error then use the negative signed value. When casted to an UN signed long it will be the "correct" value. Test this yourself in C#, it'll work e.g.
This code
static void Main(string[] args)
{
UInt32 us = 0x80004005;
Int32 s = (Int32)us;
Console.WriteLine("Unsigned {0}", us);
Console.WriteLine("Signed {0}", s);
Console.WriteLine("Signed as unsigned {0}", (UInt32)s);
Console.ReadKey();
}
will produce this output
- Unsigned 2147500037
- Signed -2147467259
- Signed as unsigned 2147500037
So it's safe to use -2147467259 for the value of E_FAIL
From WinError.h for Win32
#define E_FAIL _HRESULT_TYPEDEF_(0x80004005L)
To find answers like this, use visual studio's file search to search the header files in the VC Include directory of your visual studio install directory.
C:\Program Files\Microsoft Visual Studio 9.0\VC\include
Use the "unchecked" keyword to do this.
e.g.
const int E_FAIL = unchecked((int)0x80004005);