I've had to do some job-related learning of the Windows API lately, and while my experiences in that could fill a canyon, it has also lead me to rekindle a long-dead curiosity in the WINE Project. I began my studying by leaving the safe, loving arms of FreeBSD for an XP Pro box with a free edition of Visual C++ Express. I had heard plenty of complaints in the past about the WinAPI, but put them down to lazy Windows programmers not wanting to get their hands dirty. The truth is, the Windows API deserves complainers. It's ugly, illegible, and confusing. If your idea of GUI programming is a clean, object-oriented Qt interface, do yourself a favour and never take a look at a WNDCLASS. The fact that it's called a class is about as close as it comes to object-orientation.
Perhaps I'm being too harsh. After all, the API of Windows specifies not only GUI components, but everything about the operating system. If the FreeBSD kernel, XServer, and KDE were all combined into one disgusting, disorganised, and nonsensical blob, it would be just as painful to program. Fortunately, nobody in the *nix world is insane enough to try something like that. They also avoid wherever possible giving data types confusing and unnecessary names in all-uppercase letters. What's an HINSTANCE? It's a handle. Theoretically naming shit like this is supposed to save you time and prevent errors. It's not a 4-byte int, it's a 4-byte int redefined as a handle instance. Therefore it must be safer. Right. You know what? If you're using functions without reading the API documentation, your code probably isn't preventing any errors or saving any time anyway. And the time it takes to look in that function documentation and see what that integer represents takes all of 1 second.
Nevertheless, I progressed. Despite the fact that Visual C++ Express Edition totally lacks MFC support, which makes it pretty much useless for maintaining existing programs of any decent size that aren't crazy enough to use the Windows API directly, it was all right. But I kept asking myself, "Do I have to use this?" Every hour I spent in XP wondering if the computer would become nonresponsive at any moment or trying to calculate how many emails my undoubtedly bot-infected PC was spewing into the tubes, I could've been doing something cool and interesting in my beloved 6.2-RELEASE baby. After a total of 8 hours using Visual C++, I just said "Fuck it, there has to be a better way," and went back to the BSD box. I installed WINE, which I hadn't done since perhaps late 2005 when I toyed with it for awhile, and discovered the Winelib tools.
I'm not naive. At least not in this matter. I realise WINE isn't a perfect platform for Windows API programming; in fact, I found many a Google site shouting at curious inquirers not to try learning win32 in a WINE environment. You'd have to be crazy, they said. Well, perhaps I am...Perhaps I am.
If you're unfamiliar with the Windows API, a good starting point on the Internet is this site: http://www.relisoft.com/win32/index.htm
. It contains a few tutorials that are easy enough to follow. Where they get interesting, for me at least, is in their usage as conformance tests for WINE and Winelib's toolset. So without much further ado, I begin with Test #1 (on the tutorial site this program is called "Winnie"). What follows is basically a lazy and shameless copy and paste of the README I wrote for that archive:
This is a "book testing" approach to Wine conformance using a
website rather than a standard book. I've had to modify the
files slightly, but nothing syntactic. The proper way to test
whether this works under WINE is to perform the following commands
in the directory of the source:
winemaker --lower-uppercase .
If it compiles, you know at least your WINE installation (0.9.33)
can get as far as mine. Now copy the resulting output (for me
this file is called winnie.exe.so) to somewhere in the WINE
base directory and call it. For example, on my system it would
look like this:
cp winnie.exe.so ~/.wine/drive_c/winnie.exe
If all went well, you should now see a boring white window with
a friendly titlebar.
The source for this test can be found here: http://drlight.multics.org/winetests/winnie_winetest.tar.gz
And here's a screenshot of this exciting, do-nothing application!