May 14, 2006
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:
- 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:
<?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:
<?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!
The trackback url for this post is http://blog.kalmbachnet.de/bblog/trackback.php/80/
Comments have now been turned off for this post