Skip to main content

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:


size_t
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?

Comments

Anonymous said…
With wx 2.4.2, there are some changes:

- The line to comment out in app.cpp is line 123
- the declaration in regerror.c should be:

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

(lower case const)

- I had to grab odbc32.lib from my old VC7.0 installation and add it to the mix for linking.
Anonymous said…
So, is there a legitimate and free way to get
odbc32.lib?

It is not part of the SDK.

Thanks in advance for any pointers!
Anonymous said…
Install the XP SP2 Platform SDK, odbc32.lib is included...

Here is the link:
http://www.microsoft.com/msdownload/platformsdk/sdkupdate/XPSP2FULLInstall.htm
medalasioe said…
when I installWindows Platform SDK SDK PSDK-x86.exe, my system is winxp sp1,x86 machine,but installation show: ERROR 1311
can't find source file PSDK-AMD64_o-common.0.cab
WHY???HELP!
Anonymous said…
I have the same problem. I can also not download
PSDK-AMD64_o-common.0.cab
Anonymous said…
me to
help! thanks
Peter said…
Hello!

Which line should be commented out in the file app.cpp?
it says only that it is an #include statement.
I use wxWidgets 2.6.2 and i guess that it is a different line than the one in 2.5.2 or 2.4.2 ...
What statement should be commented out and why?

Thx for any replies,
Peter

peter.schuebel@stud.tu-ilmenau.de
Gareth said…
Oops, angle bracket problem.

It's shlwapi.h
Peter said…
Thanx for the answer.
I found out that actually shlwapi.h is no longer included at all in wxWidgets262.

Unfortunately i still cannot compile it as dll with VC8. :-(
I get 50 unresolved references when linking base.

I use Visual C++ 2005 Express with Win2003 Platform SDK and did the above mentioned things.
shazron said…
Actually, to get the additional dependencies added automatically, edit the file "<Program Files>\Microsoft Visual Studio 8\VC\VCProjectDefaults\corewin_express.vsprops"
and add the extra libs you mentioned after kernel32.lib - all separated by spaces.
Anonymous said…
I have VS2005 Team system beta 2 and widgets 2.6.2.
After implementing all the suggestions I could find, i still get unresolved dependencies (28 of them)

Some samples:
main.obj : error LNK2019: unresolved external symbol "public: void __thiscall wxStringData::Free(void)" (?Free@wxStringData@@QAEXXZ) referenced in function "public: void __thiscall wxStringData::Unlock(void)" (?Unlock@wxStringData@@QAEXXZ)

wxmswd.lib(app.obj) : error LNK2019: unresolved external symbol __imp__InitCommonControls@0 referenced in function "public: virtual bool __thiscall wxApp::Initialize(int &,char * *)" (?Initialize@wxApp@@UAE_NAAHPAPAD@Z)

etc.

My current dependencies are:
wxmswd.lib kernel32.lib shell32.lib gdi32.lib user32.lib comdlg32.lib ole32.lib oleaut32.lib advapi32.lib

There's no difference if I only list wxmswd.lib as an additional dependency. Guess the others are system defined.

I have to ignore libcmtd.lib because it conflicts with msvcrtd.lib.

Any help appreciated
Anonymous said…
Me again... Never mind, went searching for libs and found that I needed to add wxmswud.lib comctl32.lib rpcrt4.lib for a unicode build. Didn't check for non-unicode since my primary intent is a unicode app.
Anonymous said…
Looks like things changed slightly in 2.6.2. In step 11. above, the new declaration should look like:

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

instead of:

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

Note the change from 'errcode' to 'rxerrcode'.
Anonymous said…
In regard to a couple of comments about not being able to find the file PSDK-AMD64_o-common.0.cab. I had this problem and it would have been nice to have someone point out a solution. Here is mine.

If you have downloaded the image file with the PSDK and are getting this error, copy the entire PSDK install to your hard drive and try installing. I was trying to install from the MS Virtual CD device and MSI was choking on it. Best guess is that MSI, since it runs as localsystem, does not have the necessary privs on the device. There is a simmilar issue in older versions of Win2K accoring to the knowledge base.

When I copied the files to my computer to install, it worked flawlessly.
Anonymous said…
if you get such errors in vs2005:

main.obj : error LNK2019: unresolved external symbol "public: void __thiscall wxStringData::Free(void)" (?Free@wxStringData@@QAEXXZ) referenced in function "public: void __thiscall wxStringData::Unlock(void)" (?Unlock@wxStringData@@QAEXXZ)


please make sure you are using the same version library as your project (since the vs05 use unicode as default)
Anonymous said…
after a day of fiddling around with one of the 'simple' Hello World programs and giving up on it, I finally got the dialogs sample to link, but only after following the steps in this thread even though the original post is from 2004. I didn't bother making any of those code changes since I trusted them to be fixed in the wxwidget.2.8.3 release.
I have the following installed:
* Visual C++ express 2005 (v8) (includes MS .NET Framework SDK v2)
* platform SDK for windows server 2003 R2
* wxWidgets 2.8.3
Anonymous said…
Thanks for the small tutorial on the setup, helped me figure out the installation issues I was having. I have successfully used this (with some small changes) for the installer version of 2.8.4.

1. Download the Platform SDK as before, no change here.
2. Download and install the installer version for Windows (2.8.4) from the wxWidgets download page.
3. Open VC++ and goto the Options dialog from the Tools menu.
4. Add the entries needed for the Platform SDK in the 'Includes' and 'Lib' directories as before.
5. Accept the changes and close the options dialog.
6. Open the wxWidgets solution file located at 'C:\wxWidgets-2.8.4\build\msw\wx.dsw' and allow VC++ to upgrade it. (Select Yes To All when asked.)
7. Comment out the shlwapi.h include of the app.cpp if you did not download the Internet SDK, I did to make things easier.
8. As for editing the 'winconfig.h' for 'normalise line endings', I'm guessing this was removed from this file as its not there. So skip that.
9. Open the 'regex' project by clicking the + next to the project 'wxregex' in the solution explorer and then the + next to the source Source Files and open regerror.c
10. At line 52, you should see the start of the wx_regerror() function, comment out the all the lines, starting with the line that has size_t until you reach the first line with {. Next, you want to add in the following code before the '{'
size_t wx_regerror( int rxerrcode, CONST regex_t *preg, char *errbuf, size_t errbuf_size )
11. Build the solution :)