How do one create a COMException given a HRESULT?
I have P/Invoke:ed a win32-method which returns a HRESULT.
If it returns failure I wish to throw a COMException, with the standard error-text.
How should I do that?
throw new COMException(null, hResult)
COMException e = new COMException;
e.HResult = hResult;
throw e;
Or should I use some other method?
You should use Marshal.GetExceptionForHR() if you only want to get the exception, or Marshal.ThrowExceptionForHR() if want to throw it too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With