Using wxWidgets in Visual C++ Express

Microsoft did not see fit to ship Visual C++ Express with any windowing framework (MFC, ATL, WTL …). They clearly want to steer people down the .NET road.

But that doesn’t mean it can’t be done. In theory all you need is the Windows Platform SDK which is freely downloadable from MSDN. In practice, you also need a GUI framework and I’ve found that wxWidgets (né wxWindows) fits the bill perfectly.

Unfortunately it doesn’t work quite as smoothly as using the full on Visual Studio. There are a lot of linker errors to combat, but it can be done if you follow these (overly) simple instructions:

This is a revised (and much simpler) set of instructions. Thanks to Vadim Zeitlin and Gordon Klos for pointing out some flaws in the original

1. Download and install the Windows Platform SDK
Tragically you seem to need IE to do this, but never mind. It’s titled “Windows Server 2003” but it covers all the current versions of windows. You need core SDK and potentially Internet Development SDK (see point 9).

2. Download the latest version of wxWidgets and extract it to your c:\ drive
I’m using 2.5.2 – the latest bleeding edge version and you really want the windows specific version, not the full version as it inlcudes the Visual Studio project files. Using the development version is probably the cause of some of the problems. The timid could use 2.4.2 instead.

3. Open VC++ Express and get the “Options” dialog up from the “Tools” menu.

4. In the tree, open up the “Projects and Solutions” node and select “VC++ Directories”

5. Change the “Show directories…” drop list to “Include Files” and add “c:\Program Files\Microsoft SDK\include” (or wherever you installed the SDK).

6. Change to “Library Files” and add “c:\Program Files\Microsoft SDK\Lib” (or wherever).

7. Click ok to accept those changes.

8. Open up the wxWidgets Solution file in “c:\wxWidgets2.5.2\build\msw\wx.dsw” and allow Visual C++ Express to upgrade it.

9. If you could not be bothered to download the Internet SDK then in the wxWindows project open the file MSW File\app.cpp and comment out line 87 #include <shlwapi.h>

10. open c:\wxWidgets-2.5.2\src\expat\lib\winconfig.h in the editor and allow it to normalise the line endings.

11. in the regex project open the file Source Files\regerror.c.

Change the bizarre declaration:

regerror( errcode, preg, errbuf, errbuf_size)
int errcode;/* error code, or REG_ATOI or REG_ITOA */
CONST regex_t* preg;/* associated regex_t (unused at present) */
char* errbuf;/* result buffer (unless errbuf_size==0) */
size_t errbuf_size;/* available space in errbuf, can be 0 */

to the more sensible:

size_t regerror( int errcode, CONST regex_t* preg,char* errbuf, size_t errbuf_size)

12. Build the solution. Ignore the multitude of deprecated method warnings.

Having built the framework, we can now build one of the sample projects – let’s try samples/dialogs/dialogs.dsw

1. Open the workspace file, allow VC++ to upgrade the solution as normal.

2. Select the properties of the “dialogs” project.

3. In the linker/input node, add the following libraries to the “Additional Dependencies” list:

  • shell32.lib
  • gdi32.lib
  • kernel32.lib
  • user32.lib
  • comdlg32.lib
  • ole32.lib
  • oleaut32.lib
  • advapi32.lib

4. Hit the play button.

5. Observe with smug satisfaction as the window appears.

That’s it, for debug builds at least. I haven’t tried a release build yet. It can’t be any harder. Can it?