How to bypass the WinSxS for CRT/MFC/ATL DLLs

Starting with VC8, you have two options to distribute the DLL version of the CRT/MFC/ATL with your application:

  1. You can redistribute the DLLs with your application in the same directory and also put a valid manifest for these DLLs into this directory
  2. 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!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值