Click here to Skip to main content
15,887,371 members
Articles / Desktop Programming / MFC
Article

How to compile MFC code in Visual C++ Express

Rate me:
Please Sign up or sign in to vote.
4.48/5 (37 votes)
25 Oct 2008CPOL3 min read 565.3K   3.1K   105   74
How to compile your existing MFC code in Visual C++ Express.

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:

DemoMFC

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:

MFC_Express2.PNG

Now, change the "Show directories for" dropdown to "Library files", and add:

  • $(DDK_directory)\lib\mfc\i386
  • $(DDK_directory)\lib\atl\i386

Again, replace $(DDK_directory) with the path to the DDK on your machine; see the image below:

MFC_Express3.PNG

Step 5 - In the last step, you have to edit the file "afxwin.inl", which can be found in the $(DDK_directory)\inc\mfc42 directory.

In this file, from line 1033 onwards, change:

C++
_AFXWIN_INLINE CMenu::operator==(const CMenu& menu) const
    { return ((HMENU) menu) == m_hMenu; }
_AFXWIN_INLINE CMenu::operator!=(const CMenu& menu) const
    { return ((HMENU) menu) != m_hMenu; }

into:

C++
_AFXWIN_INLINE BOOL CMenu::operator==(const CMenu& menu) const
    { return ((HMENU) menu) == m_hMenu; }
_AFXWIN_INLINE BOOL CMenu::operator!=(const CMenu& menu) const
    { return ((HMENU) menu) != m_hMenu; }

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.

History

  • October 26, 2008 - Initial version of the article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Netherlands Netherlands
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

 
GeneralThis works for me [modified] Pin
Rolf Kristensen11-Mar-09 12:39
Rolf Kristensen11-Mar-09 12:39 
GeneralIt's not this simple!!! Pin
Alan194728-Dec-08 9:33
Alan194728-Dec-08 9:33 
GeneralRe: It's not this simple!!! Pin
Alan194730-Dec-08 1:39
Alan194730-Dec-08 1:39 
GeneralRe: It's not this simple!!! Pin
Danny Ruijters30-Dec-08 1:54
Danny Ruijters30-Dec-08 1:54 
GeneralRe: It's not this simple!!! Pin
Alan19479-Jan-09 3:48
Alan19479-Jan-09 3:48 
GeneralRe: It's not this simple!!! Pin
Alan19479-Jan-09 4:17
Alan19479-Jan-09 4:17 
GeneralRe: It's not this simple!!! Pin
Danny Ruijters18-Jan-09 1:37
Danny Ruijters18-Jan-09 1:37 
GeneralIn my experience... Pin
T800G28-Oct-08 7:18
T800G28-Oct-08 7:18 
Now this is a subject that is a real debate question.
2 years ago I started my hobby endeavors in c++ with "VC2005 Express + Platform SDK2003 R2 + ResEdit + WTL 8.0" combo.

I encountered the issue of compiling the MFC demo projects from CodeProject articles and I tried the MFC dll dynamic link solution using libraries from VC6, but quickly realized that if you don't use full VC pro version, it simply is not a good solution, especially if you want to go the MFC way.

Also, even as a coding beginner I haven't had much trouble quickly learning the WTL coding style because WTL is a little more than a Win32 wrapper for most of the things, and Win32 is wery well documented. The great thing with WTL (latest, 8.0) is that it compiles without a glitch with old ATL 3.0 from Platform SDK 2003.

The PlatformSDK ATL/WTL combination so far proved highly useful, I got ATL for COM development , and I yet haven't found anything that really needed MFC for "serious" development.
Although with COM it comes down to reusing existing code due to no Studio wizards for ATL, etc., but hey, I can build infotip and thumbnail handler shell extensions Big Grin | :-D .

While using the ATL/MFC from DDK is probably a good solution if you pair it up with VC2008 and WTL, this combo suffers from the lack of ANY wizards in VC2008 Express (OMG | :OMG: ), so I highly recommend PlatformSDK ATL/WTL + VC2005 approach for any coding beginner even though it takes some extra steps to set up all correctly.

I apologize for such a long post.Rose | [Rose]
GeneralRe: In my experience... Pin
Danny Ruijters29-Oct-08 1:44
Danny Ruijters29-Oct-08 1:44 
GeneralGreat Pin
ollydbg2327-Oct-08 18:26
ollydbg2327-Oct-08 18:26 
GeneralRe: Great Pin
Danny Ruijters27-Oct-08 21:42
Danny Ruijters27-Oct-08 21:42 
QuestionReally? Pin
autoxml27-Oct-08 15:00
autoxml27-Oct-08 15:00 
AnswerRe: Really? Pin
Abu Hasan27-Oct-08 18:33
Abu Hasan27-Oct-08 18:33 
GeneralRe: Really? Pin
Danny Ruijters27-Oct-08 21:45
Danny Ruijters27-Oct-08 21:45 
GeneralRe: Really? Pin
ollydbg2327-Oct-08 22:00
ollydbg2327-Oct-08 22:00 
GeneralRe: Really? Pin
Danny Ruijters27-Oct-08 22:11
Danny Ruijters27-Oct-08 22:11 
AnswerRe: Really? Pin
Alex Cohn28-Oct-08 7:54
Alex Cohn28-Oct-08 7:54 
GeneralRe: Really? Pin
David Luca19-Dec-08 12:10
professionalDavid Luca19-Dec-08 12:10 
GeneralRe: Really? Pin
twistor9618-Jan-09 1:05
twistor9618-Jan-09 1:05 
GeneralRe: Really? Pin
Danny Ruijters18-Jan-09 1:30
Danny Ruijters18-Jan-09 1:30 
GeneralRe: Really? Pin
twistor9618-Jan-09 5:12
twistor9618-Jan-09 5:12 
GeneralRe: Really? [modified] Pin
twistor9618-Jan-09 7:59
twistor9618-Jan-09 7:59 
AnswerRe: Really? Pin
rankot23-Dec-08 5:28
rankot23-Dec-08 5:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.