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.

I've been trying to compile old MFC code in VC++ 2013 Express, but am now stuck. My experience so far:

The DDK is now called WDK, and they removed MFC from it. The most recent one which includes MFC seems to be version 7.1.0, which can still be found, so I used that one.

Insanely, the above MFC has header files which include other headers under "../atl30/" although in this distribution this folder has been renamed to "../atl71/", so you either need to alter the headers or rename the ATL folder (which is what I did).

Step 5 seems unnecessary as this fix has already been included.

There are however other compilation errors/warnings in these headers. For example...

If you use *_REFLECT messages, you may get compile errors, eg ON_WM_CTLCOLOR_REFLECT complains that CtlColor should be &CtlColor. It's right. Edit afxmsg_.h and add the "&" for this and other _REFLECT messages.

Finally it compiles, but I'm stuck getting anything to run without promptly crashing.

DEBUG_NEW has changed and using the version from the old MFC will now cause a crash when arrays are correctly deleted using delete[]. With new defined to DEBUG_NEW, an array allocated with new[] will crash if deleted with delete[]. You must use delete without the []. But in VC++ 2013 if not using DEBUG_NEW then new[] must be matched by delete[] or you get another crash (didn't seem to happen in VC++ 6). So DEBUG_NEW inverts which form of delete must be used to avoid a crash.

I removed DEBUG_NEW from my code. Then it crashed in code using CArray because the MFC headers also use DEBUG_NEW. I removed that from the headers and now it crashes when calling CWnd::DestroyWindow(), presumably because use of DEBUG_NEW is compiled into the libraries which I can't do anything about.

Even a release build also crashes on start-up. So there's obviously more than DEBUG_NEW to this story.

I got some very simple test code to run successfully, but not the real code I want working.

What's to be done here? Is it a lost cause? Has anyone got this working?Thanks,Rob.

Hi, and thanks for posting these instructions. Unfortunately, the current distribution of VS 2010 Express shows this when you select VC++ Directories:

"VC++ Directories editing in Tools > Options has been deprecated."VC++ Directories are now available as a user property sheet that is added by default to all projects. Please click '?' for more more information."

"If you want to set up directory search paths (for your projects) that can be shared by other users or that can be applied across multiple computers, Visual C++ provides an alternative to this dialog box, by using project property sheets. For more information, see Property Sheets (C++)." which is a link which takes me to:

http://msdn.microsoft.com/en-us/library/a4xbdz1e%28v=vs.100%29.aspx

where one reads:

"This content has been moved to Working with Project Properties." which is a link which takes me to:

http://msdn.microsoft.com/en-us/library/669zx6zc%28v=vs.100%29.aspx

where I read:

"Although you can set "global" properties on a per-user, per-computer basis, we no longer recommend it. Instead, we recommend that you use Property Manager to create a property sheet to store the settings for each kind of project that you want to be able to reuse or share with others. Property sheets also make it less likely that property settings for other project types will be inadvertently changed. Property sheets are discussed in more detail later in this article." which is a link which takes me to:

"If you have a common, frequently used set of properties that you want to apply to multiple projects, you can use Property Manager to capture them in a reusable property sheet file, which by convention has a .prop file name extension. You can apply the sheet (or sheets) to new projects so that you don't have to set its properties from scratch. To access Property Manager, on the menu bar, choose View, Property Manager. The following illustration shows Property Manager after the shortcut menu for the Release | Win32 configuration node was opened."

However, when I look under the View menu, there is no Property Manager option, only a Properties Window under Other Windows.

Obviously, none of these complications and inconsistencies are your fault (and I subsequently found how to get the Property Manager by switching to Expert Settings under Tools -> Settings), but clearly the paradigm has changed enough now--and you appear to be enough of an expert--that I thought I'd see if you might want to update your instructions accordingly.

Am using VS2008 Express. After installing an updated DDK referenced in this thread and applying the suggestions mentioned, I was able to build a release version of DemoMFC without any errors or warnings. However, when I try to run the application from the Release folder, I get a STATUS_DLL_NOT_FOUND error saying that MFC42D.DLL was not found. It further suggests to reload the application. Any ideas why a release version of DemoMFC is needing the debug dll? Is there some setting in C++ or Linker properties that needs to be tweaked?

MFC42D.DLL is the debug version of the MFC dll, which is not delivered along with the DDK. When you have set everything to release settings, the required MFC dll is MFC42.DLL (without the 'D' after 42) which is delivered with your windows installation.

So, check all you project settings to verify that you have not enabled debug settings somewhere.

Thanks a lot for the very useful article.However isn't there a violation of the license? I mean, VS2010 express may be used in commercial products, but won't there be a problem with your trick win MFC?

P.S. Does it really matter which MFC version to hijack? For instance, I have a VS2008 installed, I could take MFC/Atl headers and libs from there.

To the best of my knowledge, there is no violation of any license. You simply download some stuff that microsoft makes available (Visual Studio Express and the Windows Driver Kit), and you configure them to work together.

P.S. Does it really matter which MFC version to hijack? For instance, I have a VS2008 installed, I could take MFC/Atl headers and libs from there.

It does not really matter which version of MFC/ATL you take. The Windows Driver Kit is simply available for download for anyone, and it contains the MFC/ATL sources. But if you have another source (like a previously bought older Visual Studio version), that will work too.

I just tried your solution but got the following error message: LINK : fatal error LNK1104: cannot open file 'uafxcwd.lib'I believe it relates to the unicode characterset. How do I get around this?I'm using VC++ 2008 Express (but with the new developers kit), I've selected release mode. Perhaps I haven't selected dynamic link correctly? My runtime library is Multi-threaded DLL.

As time passes, some things have changed (Visual Studio 2010 came along, and the Windows DDK has been updated). Luckily, Cesare Brizio has tried the approach of this article with these new developments, and emailed the results to me. I have copy-pasted that email below, so that you can reap the fruits of his work.

kind regards - Danny

Dear Danny:I am 51 years old, Italian, and I have been an IT professional for more than 25 years.As time passed, my technical engagements become less and less frequent, and since many years I became just the “communication and marketing” person of the businesses I collaborate with.But still the interest for software development emerges from time to time, so I decided to give a try to Visual Studio Express 2010, and chose c++ (a language that I know just very little) just because there was source code available for developing bitmap convolution filters and sound spectrum analyzers – the two issues that I am interested into.The burning disappointment of discovering that MFC and APL were not included (and acquiring a professional visual studio was out of question, for a simple curiosity like mine...) was soothened and then completely healed by your much welcome and exhaustive contribution (“http://www.codeproject.com/KB/MFC/MFCinVisualStudioExpress.aspx”).Now, thanks to you, I saved several hundred euros in a completely licit way, and I successfully compiled the two brilliant projects by Silviu Caragea (convolution filters) and Bartosz Milewsky (Frequency Analyzer).

The only slight differences that I found from your guidelines are the following:

1) The new address for downloading the Windows DDK is: http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=36a2630f-5d56-43b5-b996-7633f2ec14ff – While MFC is still at version 42, ATL changed from “atl30” to “atl71”

2) In Visual Studio 2010, the additional folders for include and libraries are a property of the project configuration, not of the platform configuration, and must be input separately in each project for debug mode and for release mode

3) The custom additional folders to be added to the project should include also the LIB directories from DDK

4) After installing the new Windows DDK, one should go to the inc\mfc42 folder and locate atldef.h and atlconv.h and substitute references to the “atl30” folder with the “atl71” folder.

5) the “afxwin.inl” patch that you suggested seems to be not needed anymore.

Done as follows, but I still get an error at runtime, as soon as the application is launched: "Missing MFC42D.DLL". I skipped point 3) since I have not understood what I need to do. The project compiles fine, however.

I have done as described, but still have trouble compiling the sources from http://www.withinwindows.com/2008/03/23/bluetooth-toggle-the-second-non-oem-windows-mobility-center-tile/- installed vc2010 express, sdk 7.1 and ddk 7.1- added to project's include dirs inc\crt, inc\api and inc\mfc42 from the ddk (the 1st one was needed because I was getting errors including headers from crt dir within vc's own dirs)- added to project's libdirs lib\mfc\amd64, lib\atl\amd64 from the ddk

I followed all of Brizio's steps for VS210 Express but left out step 3) which I did not understand. Could you please elaborate? After employing the remaining steps however, the output from compiling left me with only one error (all other MFC related errors dissappeared):

1>c:\users\hbr\documents\visual studio 2010\projects\hcf_12.08.31\hcf\app\hcf_axis.cpp(645): error C2039: 'GetString' : is not a member of 'CString'

c:\winddk\7600.16385.1\inc\mfc42\afx.h(385) : see declaration of 'CString'

BIG THANKS to Danny and everyone else contributing to this solution, it works for me!!I only had to add a #include "..\mfc42\afxdisp.h" to atl71\atlexcept.h because the compiler complained about not having AfxThrowOleException defined. Defining _ATL_NO_EXCEPTIONS in my projects could probably have fixed this too, but I haven't checked...