Introduction

The Microsoft Visual C++ Express edition can be downloaded free of charge. While the Express edition of Visual C++ offers a rich development environment, it lacks the possibilities to develop and compile MFC programs. In this article, I will explain how you still can compile MFC code within Visual C++ Express, which is particularly useful when you have a lot of old MFC code lying around, like I have.

Five simple steps

To compile MFC code within the Express edition of Visual C++, you first need to perform five steps:

Step 1 - First of all, you need to download and install the Visual C++ Express edition, if you have not already done so.

Step 2 - Go to the Windows Server 2003 driver development kit (DDK) webpage, download the DDK ISO file, and burn it to a CD. Most of the time, you can just use the CD burning software that comes with your computer for this task, or alternatively, you can use this software, or this.

Step 3 - Install the DDK from the CD (execute setup.exe on the CD). It is enough to simply install the default selection (Build Environment, Documentation, Tools for Driver Developers).

Step 4 - You have to add a couple of directory paths to tell Visual C++ where the MFC related files can be found. This can be done by selecting in the "Options..." entry in the "Tools" menu, like shown in the image below:

Then, in the "Projects and Solutions" entry in the list on the left, select "VC++ Directories". Now, in the "Show directories for" dropdown on the right, select "Include files". Here, you should add (simply click on an empty line) the following paths:

$(DDK_directory)\inc\mfc42

$(DDK_directory)\inc\atl30

whereby you should replace $(DDK_directory) with the directory where you installed the DDK in the previous step, which is "C:\WINDDK\3790.1830" in my case; see the image below:

Looking for the differences? Well, "BOOL" has been inserted twice (mind the capitals).

On your marks, Get set, Go!

Now, you are all set to compile MFC programs in the Visual C++ Express edition. Download the example program at the top of this article, and try it!

Aren't there any issues? Of course, there are! You just installed version 4.2 of MFC, which is the version that was delivered with Visual Studio 6. This means that if you have code that uses MFC features introduced after VS6, it will not compile. Further, you will not be able to run with the MFC debug DLLs, nor will you be able to link statically against MFC. Using dynamic linking in release mode makes everything run fine, though. Finally, the Express edition does not come with the drag and drop MFC resource editor. You can either edit your resource files (these are the files that determine how your windows look like) by hand in text mode, or you can try an external program.

Share

About the Author

As a 3D Imaging Scientist, I build clinical prototype software, mainly in the domain of 3D cardio-vascular x-ray. The value of the prototypes is evaluated in hospitals by physicians, who use them in cardio-vascular interventions. Further it is my task to stay in touch with the scientific developments in 3D medical imaging.

I have been writing software for about 20 years now. The past 6 years I concerned myself mainly with 3D medical image processing, visualization and GPU programming.

Comments and Discussions

I followed instructions above and had to add 3 more include directories and now I am stuck. It can not find richedit.h when I try to build DemoMFC. I searched hard drive and can not find it anywhere either. I have added the wxp, crt, and wnet include directories because of other errors in the setup so far.

I need help... my old MFC code was working but unfortunately I don't have anymore visual c++ (standard) and this is way I try to follow the steps described in this article, which is amazing. Thank you for having done this.

The good news: I don't have anymore the error code asking for afx files but I still have some errors and I guess it's related to the paths or the version of C++ used.

Here the errors that I have when I try to compile the code:

error C2039: 'SetPoint' : is not a member of 'CPoint' c:\winddk\3790.1830\inc\mfc42\afxwin.h(176) : see declaration of 'CPoint'error C2039: 'Trim' : is not a member of 'CString' c:\winddk\3790.1830\inc\mfc42\afx.h(369) : see declaration of 'CString'error C2228: left of '.Right' must have class/struct/union

this is big problem,I can't make it.I just downloaded WDK7.0 and vc2008 express,wdk7.0 included mfc&atl head file and lib file yet,but it is so difficult let them worked together.behind fix a lot error and warning ,eventually,I can't fix this error.

I've been struggling with this problem as well. I performed on a dumpbin /exports on mfc42.dll (from the DDK) and this function simply does not exist -- hence, the link error. I did a dumpbin and mfc80.dll from Visual Studio 2005 full version and AfxThrowInvalidArgException function is there. I don't have access to the old VS6 version of the mfc42 dlls, so I couldn't perform a dumpbin on that, but I know that I never had a problem with linking it before in VS6. I don't really have a simple solution for this problem, but this may help someone else solve it.

I have a question concerning the migration of mfc projects from VC++ 6 to VC++ 2008 Express. Is it possible to use mfc libs from VC++ 6? If yes what I need to do for that? If yes is it then still necessary to install DDK?

Follow the instructions in the article, but where it tells you to add the "$(DDK_directory)\inc\mfc42" directory, use the "C:\Program Files\Microsoft Visual Studio\VC98\MFC\Include" folder instead. Same goes for the other include and lib directories (e.g., "C:\Program Files\Microsoft Visual Studio\VC98\MFC\Lib" for the lib).

You do not need to install the DDK. Also you can build and run in debug mode, when you have the original VC++ 6 installed.

The mfc42d.dll is the debug version of the MFC dll (this means that you have been compiling in debug mode).Try compiling in release mode, the release version of the dll (mfc42.dll) is delivered with any windows version (probably also Windows 7).

I tried. All sorts of problems - I lost count at some point. Went back and forth from debug to release. I found an mfc42d.dll on the web. but I had to disable the overlaod that mfc has on new and delete. Then its running somewhat. Its late here I will try agin release tomorrow and then send you the error message I get. I even got the latest WDK from microsoft. The symptoms are mor or less the same.Danny

I don't know if anyone has found this yet, but I've seen several posts about how this only works with a dynamic link to the MFC dll's. I found that if I copy the files from the VC6 directory "Microsoft Visual Studio\VC98\MFC\Lib", into the "WINDDK\3790.1830\lib\mfc\i386" directory, without overwriting what is there, allows for a static link to MFC.

DemoMFC works great at start point for me with Express edition of Visual C++ 2008. But with a lot of errors if I use compiler option /clr. Can I overcome it? Basically I want expend DemoMFC to add some new CLR code, for example, to be able write ‘String ^ s = gcnew String(“some words”);’ in code. Thanks in advance, James

It's very helpful, and I got the point. It's quite complex, and definitly I couldn't figure out by myself, but that I want to know. I really want to know it's how difficult to compile a VC++ project with VC++ Express as it is created in VC++ Pro, plus some code lines and procedures are dirrectly copied from VC++ 6.