Demion
Demion

Reputation: 867

Win32 API failure

Is it necessary to check all Win32 APIs return values? For example, functions like AdjustWindowRect, SetWindowLong, GetWindowLong etc. can really fail (have an internal error) or the return value is mostly a fail-safe mechanism of not inputting wrong arguments?

Upvotes: 3

Views: 1375

Answers (1)

user824425
user824425

Reputation:

Unlike POSIX, it seems that the Win32 API doesn't give a nice list of error conditions for every call. Although some functions can't fail in practice (except in the case of bad arguments), they can fail in theory. Just like you shouldn't trust user input, you also shouldn't blindly trust poorly documented libraries.

I think the best way to deal with the APIs is to wrap all calls in functions to do the error checking (which differ widely between and within the APIs), so that you have sort of a "higher level" API where all peculiarities are ironed out. You can then translate successes, errors, and warnings to whatever technique is suitable in your language (e.g. exceptions, error/warning callbacks, sum types).

Upvotes: 2

Related Questions