3 ms·
I'm sorry but that code sample is an incomprehensible eyesore. And I've written PHP4.
by philipwhiuk 3y ago
I'm sorry but that code sample is an incomprehensible eyesore.
And I've written PHP4.
- LASR 3y agoWhat's crazy is that I didn't even realize it until you pointed it out. I've been doing Win32 for so long it's like reading the green symbols in The Matrix. This all looks "normal" to me.
- zerr 3y agoBesides being unreadable, it is well known that Win32 API code is unwritable. It is only copy/paste-able.
- jeroenhd 3y agoWindows headers like uppercase. They also like very explicit types, as far as the language accepts them, of course. For example, HRESULT really is just a 32 bit integer with special rules (top bits set subsystem that cause the error, bottom bits set error code, hence the conversion function for best practice). Stripping out the Windows types and compile-time validation and the wrappers, and picking non-Windows error codes, you can turn the code into more Unix-like C++: int32_t CreateWidget(int32_t* widget) { *widget = nullptr; return ECANCELED; } int32_t GetWidgetAliases(wchar_t* aliases, uint16_t capacity, uint16_t* actual) { *actual = 0; return EBADF; } int32_t EnableWidget(int32_t widget, bool value) { return EBADF; } int32_t Close(int32_t widget) { return EBADF; } However, this code may not function if you're building for 32-bit Windows and it may not work on every compiler; it just assumes certain bit sizes that the API only guarantees in the form of typedefs.