Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain the c++ FAILED function?

Tags:

c++

windows

com

I've seen a lot of example c++ code that wraps function calls in a FAILED() function/method/macro. Could someone explain to me how this works? And if possible does anyone know a c# equivalent?

like image 977
Adam Naylor Avatar asked Dec 30 '22 07:12

Adam Naylor


1 Answers

It generally checks COM function errors. But checking any function that returns a HRESULT is what it's meant for, specifically. FAILED returns a true value if the HRESULT value is negative, which means that the function failed ("error" or "warning" severity). Both S_OK and S_FALSE are >= 0 and so they are not used to convey an error. With "negative" I mean that the high bit is set for HRESULT error codes, i.e., their hexadecimal representation, which can be found in, e.g., winerror.h, begins with an 8, as in 0x8000FFFF.

like image 101
Johann Gerell Avatar answered Jan 06 '23 12:01

Johann Gerell