Starting with VC8, you have two options to distribute the DLL version of the CRT/MFC/ATL with your application:
- You can redistribute the DLLs with your application in the same directory and also put a valid manifest for these DLLs into this directory
- You can install the redist.exe and the DLL will be installed in the WinSxS folder (on XP and later)
So, if you want to be independed from global DLLs, you might think that you can simply put the DLLs into your applications directory. But this is a false conclusion.
If a DLL is installed in the WinSxS folder, the local DLLs will be ignored. This might be even true, if a newer DLL was installed (for example by security hotfixes). This is possible due to policy redirections of these SxS-DLLs.
In most cases this also makes sense, because you always get the latest (hopefully compatible) version of the DLL.
But there might be some situations in which you might have full control over which DLLs are loaded from where. Now, Andre Stille (an other VC++ MVP), found a very simple solution : just remove the “publicKeyToken” attribute from the manifests!
So an application manifest looks like:
Application.exe.manifest:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<dependency>
<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC80.CRT"
version="8.0.50727.42" processorArchitecture="x86" />
</dependentAssembly>
</dependency>
</assembly>
You must also set the correct verion-number of the DLL! And remove the “publicKeyToken” attribute.
The manifest the for DLL looks like:
Microsoft.VC80.CRT.Manifest:
<?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.42" processorArchitecture="x86"></assemblyIdentity>
<file name="msvcr80.dll"></file>
<file name="msvcp80.dll"></file>
<file name="msvcm80.dll"></file>
</assembly>
Now the CRT DLLs in the WinSxS will be ignored and only the local DLLs will be loaded.
Thanks again to Andre Stille!
本文介绍了VC8环境下两种发布CRT/MFC/ATL DLL版本的方法,并提供了一种简单解决方案,通过修改manifest文件中的“publicKeyToken”属性,使得应用程序能够优先加载本地DLL而非全局DLL,从而实现完全控制。

被折叠的 条评论
为什么被折叠?



