App does not run with VS 2008 SP1 DLLs, previous version works with RTM versions

I have battled this problem myself last week and consider myself somewhat of an expert now 😉

I’m 99% sure that not all dlls and static libraries were recompiled with the SP1 version. You need to put

#define _BIND_TO_CURRENT_MFC_VERSION 1
#define _BIND_TO_CURRENT_CRT_VERSION 1

into every project you’re using. For every project of a real-world size, it’s very easy to forget some small lib that wasn’t recompiled.

There are more flags that define what versions to bind to; it’s documented on http://msdn.microsoft.com/en-us/library/cc664727%28v=vs.90%29.aspx . As an alternative to the lines above, you can also put

#define _BIND_TO_CURRENT_VCLIBS_VERSION 1

which will bind to the latest version of all VC libs (CRT, MFC, ATL, OpenMP).

Then, check what the embedded manifest says. Download XM Resource Editor: http://www.wilsonc.demon.co.uk/d10resourceeditor.htm. Open every dll and exe in your solution. Look under ‘XP Theme Manifest’. Check that the ‘version’ attribute on the right-hand side is ‘9.0.30729.1’. If it’s ‘9.0.21022’, some static library is pulling in the manifest for the old version.

What I found is that in many cases, both versions were included in the manifest. This means that some libraries use the sp1 version and others don’t.

A great way to debug which libraries don’t have the preprocessor directives set: temporarily modify your platform headers so that compilation stops when it tries to embed the old manifest. Open C:\Program Files\Microsoft Visual Studio 9.0\VC\crt\include\crtassem.h. Search for the ‘21022’ string. In that define, put something invalid (change ‘define’ to ‘blehbleh’ or so). This way, when you’re compiling a project where the _BIND_TO_CURRENT_CRT_VERSION preprocessor flag is not set, your compilation will stop and you’ll know that you need to add them or made sure that it’s applied everywhere.

Also make sure to use Dependency Walker so that you know what dlls are being pulled in. It’s easiest to install a fresh Windows XP copy with no updates (only SP2) on a virtual machine. This way you know for sure that there is nothing in the SxS folder that is being used instead of the side-by-side dlls that you supplied.

Leave a Comment