Click here to Skip to main content
12,819,727 members (38,773 online)
Click here to Skip to main content
Add your own
alternative version


73 bookmarked
Posted 12 Jun 2007

Create projects easily with private MFC, ATL and CRT assemblies

, 15 Jun 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
An easy way to create programs that use CRT, MFC and ATL library DLLs from application local folders


Up until VC++ 7.1 (VS.NET 2003), it was easy to deploy programs that use either the CRT-DLLs or the MFC shared DLLs. Just copying the runtime DLLs into the target directory with the executable would allow it to run.

This stopped suddenly with VC++ 8.0 (VS 2005). Programs that use the CRT and MFC with the shared DLL versions can't easily copy the runtime DLLs into the local application folder and run the application. This will work on Windows 2000, but not on Windows XP and Windows Vista. The reason is that VC++ 8.0 binds the CRT and MFC -- and ATL, if used -- with a manifest to the EXE. This manifest tells the loader to pull the files from the Side by Side (SxS) storage of the current Windows system.

So, if the runtime files are not installed in the SxS storage the program can't run, even if the needed files are in the current application folder. You have to install the runtime library files on the machine with the appropriate MSI merge module or installer. See the article about vcredist_x86.exe for more details.

A lot of developers therefore decided to link statically to the MFC and CRT to avoid this. However, in a lot of cases it is not possible to use the static linked versions of the libraries, such as when using MFC extension DLLs. The way to use the MFC and CRT as private assemblies is well-known and you might find some postings, forums, articles or blogs that address this.

Using private assemblies for runtime files allows easy xcopy deployment. No bootstrapping or MSI installer is needed in this case. To use private assemblies of the runtime files, it is necessary to extract the runtime files and modify the created manifest manually. I don't like to edit manifests. There are too many mistakes you can make. Also, you have to modify the standard way in which C++ projects are created. Again, I don't like much intelligence in the project settings. I like code that controls the project as much as possible.

So, I asked myself if there was a way to reuse the current code and to change its behavior such that manifests are automatically created which support private application local assemblies. The result is this project.


When you create a standard program with VC++ 8.0 using the shared DLLs of the MFC and the CRT, the following manifest gets created:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
      <assemblyIdentity type='win32' name='Microsoft.VC80.CRT' 
          version='8.0.50727.762' processorArchitecture='x86' 
      <assemblyIdentity type='win32' name='Microsoft.VC80.MFC' 
          version='8.0.50727.762' processorArchitecture='x86' 
      <assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls'
          version='' processorArchitecture='x86' 
          publicKeyToken='6595b64144ccf1df'language="'*'" />

The publicKeyToken attributes tell the loader in a Windows XP/2003/Vista system to look into the SxS storage for the needed DLLs. So, if we remove the publicKeyToken entries from the manifest, the program will no longer use the public installed files. It has been changed to use the requested assemblies private and application local.

Now let us remove the tokens. The manually created manifest to be used must still be included into your executable. We can't use the automatically created one. Neither can we use the automatic mechanisms in the project that collects all manifest dependencies from the source code, compiles it into a single manifest and appends it to the application. I will return to this problem later, when I describe the code.

Create private copies of the MFC and CRT assemblies

If we want to use the MFC and CRT as private copies, we have to prepare the assemblies. It is not sufficient to copy the needed files. You have to do this preparation for the CRT files, the MFC files, the MFC locale files and, finally, the ATL DLLs if applicable. And that's not all. You have to do it twice: once for the release mode files and once for the debug mode files. Remember that you are only allowed to redistribute the release mode files.

The files are ready to copy in the Visual Studio directory structure. You find the release mode files in the folder C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86. The debug mode files are located in the folder C:\Program Files\Microsoft Visual Studio 8\VC\redist\Debug_NonRedist\x86. I will now describe the procedure involving the CRT release mode files. In my case, these were the VS-2005 SP1 files, version 8.0.50727.762.

First, we copy the CRT files into our application folder. We use the files from C:\Program Files\Microsoft Visual Studio 8\VC\redist\x86\Microsoft.VC80.CRT. We then find the files msvcr80.dll, msvcp80.dll, msvcm80.dll and Microsoft.VC80.CRT.manifest. Now we need to make some small changes to this manifest file to make it private application local assembly. We must remove the publicKeyToken entries from it, but we don't need to modify any other parts.

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <noInheritable />
  <assemblyIdentity name="Microsoft.VC80.CRT" version="8.0.50727.312" 
      processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"
      type="win32" />
  <file hash="58985c4d847f19365d93fb8703e78c2b1ae57500" hashalg="SHA1" 
      name="msvcr80.dll" xmlns:cmiv2="urn:schemas-microsoft-com:asm.v3" 
    <asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2">
      <dsig:Transforms xmlns:dsig="">
            Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
      <dsig:DigestMethod xmlns:dsig="" 
          Algorithm="" />
  <file hash="3bf3838264659c30b657fd2176c9cbf4adb5b067" 
      hashalg="SHA1" name="msvcp80.dll" 
      xmlns:cmiv2="urn:schemas-microsoft-com:asm.v3" cmiv2:sourceName="">
    <asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2">
      <dsig:Transforms xmlns:dsig="">
            Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
      <dsig:DigestMethod xmlns:dsig="" 
          Algorithm="" />
  <file hash="aacedb76716864fbcadae5b167eb7ab8dc809fe8" hashalg="SHA1" 
      name="msvcm80.dll" xmlns:cmiv2="urn:schemas-microsoft-com:asm.v3" 
    <asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2">
      <dsig:Transforms xmlns:dsig="">
            Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
      <dsig:DigestMethod xmlns:dsig="" 
          Algorithm="" />

If you want, you can simplify the manifest by removing the schema hints in it. The final simplified manifest looks very simple indeed.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity type="win32" 
      name="Microsoft.VC80.CRT" version="8.0.50727.762" 
  <file name="msvcr80.dll" hash="10f4cb2831f1e9288a73387a8734a8b604e5beaa" 
  <file name="msvcp80.dll" hash="b2082dfd3009365c5b287448dcb3b4e2158a6d26" 
  <file name="msvcm80.dll" hash="542490d0fcf8615c46d0ca487033ccaeb3941f0b" 

Now repeat these steps for the MFC and ATL DLLs. If you want, you can repeat this for the debug mode files too. I use private assemblies for the release mode and debug mode files. For testing purposes, it is of interest to embed the debug mode DLLs as private assemblies. This is because you can't install the debug mode runtime files on a second test machine without installing Visual Studio 2005. There is no official MSI package to just get the debug mode files on a machine out of the box.

You will find the modified release mode files in separate ZIP files at the top of this article. I can't upload the debug files, as the EULA doesn't allow this. However, with this description it should be simple to create your own copies of them. Another way to gain the files above is to use them directly from the side by side storage.Here is a complete list of the folder names in side by side storage (C:\Windows\winsxs):

CRT Debugx86_microsoft.vc80.debugcrt_1fc8b3b9a1e18e3b_
CRT Releasex86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_
MFC Debugx86_microsoft.vc80.debugmfc_1fc8b3b9a1e18e3b_
MFC Releasex86_microsoft.vc80.mfc_1fc8b3b9a1e18e3b_
MFC localex86_microsoft.vc80.mfcloc_1fc8b3b9a1e18e3b_

The matching manifests are in the folder C:\Windows\winsxs\Manifests, with the same name as in the table above. If you want to use these files, you have to rename the manifest files to the plain assembly name, i.e. microsoft.vc80.crt.manifest for the release mode CRT assembly.

Where to place the runtime library files

The easiest and most compatible way is to place all DLLs and manifest files in the same folder as your executable. This works for Windows 2000, Windows XP and Vista. If you want, though, you can place all the files of one assembly into a subdirectory named as the desired manifest. If you look in the associated ZIP files, you will find all of the library files arranged in this way. If the loader is requested to search for a manifest named microsoft.vc80.mfc, it also searches the application folder for a directory with the name of this manifest. All files belonging to this assembly -- including the manifest file -- have to be stored into such a subdirectory.

Remember that this file layout will not work with Windows 2000. If you plan an xcopy distribution that runs on Windows 2000 too, you should place all runtime library files in the same folder as the executable.

Results up to now

At this point, we have succeeded in creating an application that loads the runtime library files from the application's local storage. We need to do this just once. The only problem that remains is this: We always need to modify the projects that the automatically created manifests ignore. We have to remove the publicKeyToken entries and we have to embed this new manifest into our application. As I mentioned above, though, it would be nice if we could just modify the manifest with some code and still use the same techniques without touching the project settings.

Using the code

If you include the header file UseMSPrivateAssemblies.h before you include any other CRT or MFC header file, everything is done automatically. You will find that your project compiles and creates a manifest that doesn't use the public side by side assemblies.

Note: It is extremely important that you include this file before any other CRT and MFC header is used. The best location in which to include this file is the stdafx.h file of your project, just at the top, before any define or other include file is used.

Please also note that the ATL and MFC locale defines are commented out in this header file. Feel free to place #ifdef statements around them. The use of ATL.DLL is rare. Also, the MFC locale DLLs must not be loaded via an assembly manifest. The MFC can find them in the current application folder without any further action.

How does it work?

The first thing the code does is define the preprocessor variables _STL_NOFORCE_MANIFEST, _CRT_NOFORCE_MANIFEST, _AFX_NOFORCE_MANIFEST and _ATL_NOFORCE_MANIFEST (only if you use it). These defines prevent the MS header files from ejecting #pragma comment statements with the manifest information of the used CRT and MFC. Using these defines is very wise in library files. In this case, no manifest entries are created from our object code and the code that uses your library is free to define the needed assemblies.

However, this is not enough. If you just define the preprocessor variables, you don't create manifest entries from your compiled code. When you link to the CRT or the MFC files, two object files are pulled from the libraries that again create some manifest entries. It is easy to force the linker to not include these object files by defining a few variables.

int _forceCRTManifest;
int _forceMFCManifest;
int _forceAtlDllManifest;

The variables have to be defined as extern "C". As you can see in the original source code, I declared them with __declspec(selectany). This was to prevent the linker from firing an error because of the multiple definitions that the linker will find of these variables when the header file is used in more than one module.

Finally, we want to create our manifest that defines the assemblies as private. Again, this is easy as long as the base versions of all runtime files are the same. I just use the header file crtassem.h from the CRT code to get the correct version and names. The created manifest entries reflect the debug and release mode, as you can see in the following source code.

#ifdef _DEBUG
#define __LIBRARIES_SUB_VERSION    "Debug"
// Manifest for the CRT
#pragma comment(linker,"/manifestdependency:\"type='win32' " \
    "version='" _CRT_ASSEMBLY_VERSION "' " \
    "processorArchitecture='x86' \"")
// Manifest for the MFC
#pragma comment(linker,"/manifestdependency:\"type='win32' " \
    "version='" _CRT_ASSEMBLY_VERSION "' " \
#pragma comment(linker,"/manifestdependency:\"type='win32' " \
    "version='" _CRT_ASSEMBLY_VERSION "' " \

Feel free to add #ifdefs and other stuff to this header file to make it more flexible. Maybe this is work for a version 1.1.

Why should we not use the original manifests?

What would happen if you used the unchanged manifests in the application directory? Wouldn't it work?

Yes! It would work. Unfortunately, you can't control what assemblies are loaded. If the needed assemblies are in the SxS storage too, then the loader of the OS will choose the files from there. If the files are not installed in the SxS storage, then the local files in the application folder will be used. If a new service pack is installed in the side by side storage, i.e. SP2, these files will be loaded and executed. The application local files are ignored. So, using the files in this way is a kind of fallback solution. However, it is possible to get some kind of xcopy installation this way.

Thanks to my co-MVP Hans Dietrich for pointing this out.

Get the sample to run

Even after you've compiled the sample, it will not run as long as you haven't copied the needed runtime files into the application directory or subdirectories! So, don't wonder if you get an error. You can find the release mode runtime library files in a separate ZIP file.

Final tips

You don't need a manifest for the MFC locale files. You might just copy them into the application folder. This works fine. The MFC always tries to load the files first by the internal manifest. If it can't find the files, it loads them from the application directory. The MFC files always contain a UNICODE and an MCBS version. You might need only one. Feel free to modify the manifest file for the MFC DLLs and just ship the version that you really need.

That's it; have fun with this. Happy coding and God bless you all.


  • 12 June, 2007 -- Version 1.0: first basic version for VC++ 8.0
  • 13 June, 2007 -- Version 1.1: simplified description and added some notes from the current discussion


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


About the Author

Martin Richter [MVP C++]
Software Developer (Senior)
Germany Germany
MVP for C++ in Germany from 2000 up to 2015.
Developer since 1979, working with C/C++ since 1982
Started with Windows development in 1990

Love my bicycles (specially my recumbent) and geocaching

You may also be interested in...


Comments and Discussions

QuestionWorks well, any idea how to do that with Vs2008? Pin
__PPS__9-Jul-13 10:42
member__PPS__9-Jul-13 10:42 
AnswerRe: Works well, any idea how to do that with Vs2008? Pin
__PPS__9-Jul-13 10:54
member__PPS__9-Jul-13 10:54 
Generalerror message when trying to use private manifest for ATL Pin
xairoy26-May-11 6:22
memberxairoy26-May-11 6:22 
GeneralRe: error message when trying to use private manifest for ATL Pin
Martin Richter [MVP C++]26-May-11 11:53
memberMartin Richter [MVP C++]26-May-11 11:53 
Questionvcomp.dll Pin
xairoy31-Jan-11 3:32
memberxairoy31-Jan-11 3:32 
AnswerRe: vcomp.dll Pin
Martin Richter [MVP C++]3-Feb-11 2:38
memberMartin Richter [MVP C++]3-Feb-11 2:38 
Same as described here.
1. Copy all files like described here.
2. Prepare the manifest files (remove publickey entries).
3. Prepare the manifest file for your app, so it doesn't contain any publeykey entries too.

Should work in the same way.
Martin Richter (MVP for C++) WWJD
"A well-written program is its own heaven; a poorly written program is its own hell!" The Tao of Programming

GeneralQuick guide - Here are the steps to get this working: Pin
assaf raman26-Aug-09 3:29
memberassaf raman26-Aug-09 3:29 
GeneralCan't get sample to work as is Pin
David Fenstemaker10-Aug-09 13:41
memberDavid Fenstemaker10-Aug-09 13:41 
QuestionHow to run the sample application under System32? Pin
nthnhung26-Mar-09 3:16
membernthnhung26-Mar-09 3:16 
AnswerRe: How to run the sample application under System32? Pin
Martin Richter [MVP C++]27-Mar-09 4:19
memberMartin Richter [MVP C++]27-Mar-09 4:19 
AnswerRe: How to run the sample application under System32? Pin
nthnhung27-Mar-09 22:26
membernthnhung27-Mar-09 22:26 
QuestionError :application configuration is incorrect Pin
DipaliPawar23-Feb-09 4:44
memberDipaliPawar23-Feb-09 4:44 
AnswerRe: Error :application configuration is incorrect Pin
Martin Richter [MVP C++]23-Feb-09 8:51
memberMartin Richter [MVP C++]23-Feb-09 8:51 
AnswerRe: Error :application configuration is incorrect Pin
Hadi Dayvary30-Aug-09 23:44
memberHadi Dayvary30-Aug-09 23:44 
GeneralSample gives error when executed Pin
SunilApte22-Feb-09 21:43
memberSunilApte22-Feb-09 21:43 
GeneralRe: Sample gives error when executed Pin
Martin Richter [MVP C++]23-Feb-09 8:52
memberMartin Richter [MVP C++]23-Feb-09 8:52 
GeneralRe: Sample gives error when executed Pin
SunilApte26-Feb-09 4:01
memberSunilApte26-Feb-09 4:01 
GeneralSame Problem Pin
simcon9422-Jan-09 5:48
membersimcon9422-Jan-09 5:48 
GeneralRe: Same Problem Pin
Martin Richter [MVP C++]23-Jan-09 2:42
memberMartin Richter [MVP C++]23-Jan-09 2:42 
GeneralRe: Same Problem Pin
simcon9423-Jan-09 4:51
membersimcon9423-Jan-09 4:51 
GeneralRe: Same Problem Pin
Martin Richter [MVP C++]23-Jan-09 5:54
memberMartin Richter [MVP C++]23-Jan-09 5:54 
GeneralRe: Same Problem Pin
simcon9423-Jan-09 6:15
membersimcon9423-Jan-09 6:15 
GeneralRe: Same Problem Pin
Martin Richter [MVP C++]23-Jan-09 7:34
memberMartin Richter [MVP C++]23-Jan-09 7:34 
QuestionManifest includes both "local" and publicKeyTokens? Pin
Member 29309897-Jan-09 22:49
memberMember 29309897-Jan-09 22:49 
AnswerRe: Manifest includes both "local" and publicKeyTokens? Pin
Martin Richter [MVP C++]8-Jan-09 6:25
memberMartin Richter [MVP C++]8-Jan-09 6:25 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 15 Jun 2007
Article Copyright 2007 by Martin Richter [MVP C++]
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid