(Some) Visual C++ Express Edition 2005 Gotchas

Visual C++ Express Edition Gotchas

Moving from VC6 to Visual C++ Express Edition has thrown up some issues (and no doubt will continue to do so). The following table lists the main problems (and their solutions) I’ve encountered so far. The really nice thing is that these problems could be easily anticipated and users warned, but hey, where’s the fun in that?

I ran into a few problems during installation and when compiling my existing code for the first time. I found that solutions to installation problems were adequately covered on the MS web-site. Solutions to compilation problems were a bit more difficult to find, hence this page…


I use Microsoft because it’s what I use at work and it’s the de facto “industry standard”. Over time I plan to dabble with other free compilers…

I switched from Visual C++ 6.0 (VC++6) to Visual C++ Express Edition (VCEE), it’s free so I ain’t complaining. I’ve also installed the Windows SDK and MSDN, again both available free from MS. The MSDN is a wonderful resource blighted by a truly appalling interface and filters that don’t work (the “developers” should be mightily ashamed of themselves). Bizarrely, the SDK is labelled “Microsoft Platform SDK for Windows Server 2003 SP1”, but no, that is the latest version and the one to download and install.

Summary

Error, warning or problem Solution
foo.cpp(18035) : warning C4996: 'function' was declared deprecated Disable appropriate warning detail…
error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR' Set project defaults to use Multi-Byte Character Set (MCBS) detail…
error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR' Set project defaults to use Multi-Byte Character Set (MCBS) detail…
RC1015: cannot open include file 'afxres.h' Edit resource file manually detail…
Express does not allow the editing of resources Use third party editor then include manually detail…
Run time error:
Couldn't run application because MSVCR80D.dll couldn't be found/is missing.
Link statically to the C run-time (CRT) using the /MT compiler switch detail…

This is a re-distribution issue. See Running a very simple Win32 app on a comp without VC++ 2005 Express

 

Detail

warning C4996: 'function' was declared deprecated

Fix

To fix on a per project or per file basis add
#pragma warning(disable : 4996)
To fix for all projects
either
Ensure that the project is selected (from Solution Explorer or Property Manager) then
Project → Properties → Configuration Properties → C/C++ → Preprocessor
add

;_CRT_SECURE_NO_DEPRECATE

to Preprocessor Definitions

or

add
<Tool Name="VCCLCompilerTool" PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE"/>
to Visual Studio 8\VC\VCProjectDefaults\corewin_express.vsprops inside the VisualStudioPropertySheet tags. (The CoreWin.vsprops file should be Read-Only, so you may have to change its file properties before saving.)

Comments

A double whammy. On the one hand, this version is more standards compliant that previous versions, so code that relies on non-conformance will unexpectedly break. On the other hand, MS have unilaterally and without authority declared standard functions deprecated, so VALID code will unexpectedly break.And best of all…

Not portable! Not portable! Not portable!

Nice.

I’d read about the “deprecation” issue around the web. Apparently MS know better and have greater authority than the C++ standards committee (which is nice to know) so this little ditty breaks the perfectly valid code of thousands of developers. Yay! Go Redmond!


error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR'
error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR'

Fix

Project → Properties → Configuration Properties → General → Character Set
Set to use Multi-Byte Character Set

Comments

The MCBS problem completely blindsided me. It all makes you wonder why they can’t leave their self-evidently “God’s gift” improvements turned off by default and let the programmer turn them on at their discretion. Do Microsoft have such a low opinion of their customers?

RC1015: cannot open include file 'afxres.h'

Fix

Edit the appropriate resource file (usually projectname.h) removing the references to afxres.h.This will happen when trying to compile a VC++ Standard or Professional project with Express. Standard and Professional add a resource file which contains something like this:

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.K.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#pragma code_page(1252)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE 
BEGIN
    "resource1.h\0"
END

2 TEXTINCLUDE 
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE 
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED

/////////////////////////////////////////////////////////////////////////////
//
// Icon
//

// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1               ICON                    "icon1.ico"
#endif    // English (U.K.) resources
/////////////////////////////////////////////////////////////////////////////

#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//

/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

most of which isn’t needed. The preceding can be replaced with:

#include "resource.h"
IDI_ICON1               ICON                    "icon1.ico"

Comments

Even though there is no Resource Editor with Express afxres.h could easily have been included with Express to avoid this error when sharing projects between little and big brother, but we have to use yet another half-arsed workround instead.


Express does not allow the editing of resources

Fix

Use third party editor then include manually. While it’s a pain to find an editor, it’s not as difficult to add the files to a project as one might suppose, as this tutorial at winprog.org shows.

Comments

I think I read a comment in the MSDN forums that the resource editor may be included in future versions.


Couldn't run application because MSVCR80D.dll couldn't be found/is missing

Fix

Ensure that the project is selected (from Solution Explorer or Property Manager) then
Project → Properties → Configuration Properties → C/C++ → Code Generation → Runtime LibrarySet the /MT option.

Comments

At one point I thought I might have to port my app over to Dev-C++ or something but in the end, I changed this setting and the resulting exe ran on a WinME box, so this fix should be pretty much bullet-proof.There’s quite a lot of noise over on the MSDN forums, hereherehere or here for example, but this fix is surprisingly simple and straightforward, just well-hidden, although the exe balloons from ~80kB to ~260kB.

Let’s just consider this for a minute, select “release build” then click build and you get an exe you CAN’T release.

Hmmm… so once again… set the release build option… y’know so you can build an exe to give to OTHER people who probably won’t have any Visual Studio tools installed, click build and Express builds an exe… that y’know OTHER people on entirely DIFFERENT computers CAN’T USE!!!

So, no warnings, no instructions, no options, no indication that Express will not do what you’ve asked for, no indication of how to do it, nothing. Quick check in the dictionary for the definition of contempt… a-a-and… no, no mention of MicroSoft’s attitude towards their customers.

The truly staggering thing to me is that someone sat down and decided that this was a GOOD idea! Take a moment, if you will, and picture a conference room full of Redmond’s finest; slumped, slack jawed, vacant eyed and drooling, barely able to remember how to breathe when some genius pipes up “Programmers never really want to share their work with anyone else ever. So, when they ask for a release exe they don’t really want a release exe. So, we should cripple it and not tell then… hur, hur, hur.” before succumbing to an aneurysm as his synapses collapse under the strain of actually having a thought (no matter that it’s total pants). Several days later, half-starved and wild-eyed they finally remember how to exit the room (thank God the door wasn’t closed or they wouldn’t have made it out alive). Determined that their fellow shall not have died in vain they will implement his idea… er… whatever it was…

I must admit I’m particularly pissed off because I’ve been sending out copies of a simple demo app to show off my programming prowess and now I find that they probably won’t work on the target machines. So, MS have made me look more like a programming retard than a programming demi-god. Thanks a big fat hairy bunch guys… that plumbing job is starting to look mighty fine…

Moral: don’t trust those arrogant asses at MS…


Disclaimer: All opinions expressed here are just that; my opinions; and are in no way intended to criticise Microsoft, its staff or products…
no matter how poor that may actually be.