Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good idea to recreate Win32's headers?

Tags:

c

header

winapi

I'm finding myself doing more C/C++ code against Win32 lately, and coming from a C# background I've developed an obsession with "clean code" that is completely consistent, so moving away from the beautiful System.* namespace back to the mishmash of #defines that make up the Win32 API header files is a bit of a culture shock.

After reading through MSDN's alphabetical list of core Win32 functions I realised how simple Win32's API design actually is, and it's unfortunate that it's shrouded with all the cruft from the past 25 years, including many references to 16-bit programming that are completely irrelevant in today's 64-bit world.

I'm due to start a new C/C++ project soon, and I was thinking about how I could recreate Win32's headers on an as-needed basis. I could design it to be beautiful, and yet it would maintain 100% binary (and source) compatibility with existing programs (because the #defines ultimately resolve the same thing).

I was wondering if anyone had attempted this in the past (Google turned up nothing), or if anyone wanted to dissuade me from it.

Another thing I thought of, was how with a cleaner C Win32 API, it becomes possible to design a cleaner and easier to use C++ Win32 API wrapper on top, as there wouldn't be any namespace pollution from the old C Win32 items.

EDIT:

Just to clarify, I'm not doing this to improve compilation performance or for any kind of optimisation, I'm fully aware the compiler does away with everything that isn't used. My quest here is to have a Win32 header library that's a pleasure to work with (because I won't need to depress Caps-lock every time I use a function).

like image 850
Dai Avatar asked May 27 '11 01:05

Dai


2 Answers

Don't do this.

It may be possible, but it will take a long time and will probably lead to subtle bugs.

However, and more importantly, it will make your program utterly impossible for anyone other than you to maintain.

like image 158
SLaks Avatar answered Nov 09 '22 16:11

SLaks


There's no point in doing this. Just because there's additional cruft doesn't mean it's compiled into the binary (anything unused will be optimized out). Furthermore, on the EXTREME off-chance that anything DOES change (I dunno, maybe WM_INPUT's number changes) it's just a lot easier to use the system headers. Furthermore, what's more intuitive? I think #include <windows.h> is a lot easier to understand than #include "a-windows-of-my-own.h".

Also, honestly you never should need to even look at the contents of windows.h. Yeah I've read it, yeah it's ugly as sin, but it does what I need it to and I don't need to maintain it.

Probably the ONLY downside of using the real windows.h is that it MAY slow down compilation by a few milliseconds.

like image 25
Chris Eberle Avatar answered Nov 09 '22 16:11

Chris Eberle