Thursday, December 07, 2006

 

Some notes on Visual Studio 2005 - 3

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

从某牛人的blog看到的

May 14, 2006How 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:

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!

一个更牛的问题是如何在win2000等环境中使用XP的效果,这个MSDN板上的某大牛干过,据说手工扒了N多WindowsXP文件过去,再修改调用方式,不过没有透露细节,可叹可叹

2.
如果想简单一点也可以这样偷懒

from http://www.cnblogs.com/wuhanhoutao/archive/2008/01/09/1031928.html

解决"应用程序配置不正确,程序无法启动"

在使用 VC++2005环境下生成的程序,放置到未安装VC环境的机器下后,有时候会出现程序无法执行的错误,其提示是:应用程序配置不正确,程序无法启动,重新安装应用程序可能解决问题。

实际上,重装是解决不了问题的,解决的一种方法是查看*exe.intermediate.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.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
/dependentAssembly>
/dependency>
dependency>
dependentAssembly>
assemblyIdentity type='win32' name='Microsoft.VC80.MFC' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
/dependentAssembly>
/dependency>
dependency>
dependentAssembly>
assemblyIdentity type='win32' name='Microsoft.VC80.DebugCRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
/dependentAssembly>
/dependency>
/assembly>

需要注意这个文件中的3个关键词:Microsoft.VC80.CRT,Microsoft.VC80.MFC和Microsoft.VC80.DebugCRT。寻找到...."Program Files"Microsoft Visual Studio 8"VC"redist文件夹下面,找到这些名称的子文件夹,拷贝它们下面所有的文件到希望发布的EXE文件下面,一起打包。这些文件也就是mfc80.dll,msvcr80.dll,msvcp80.dll和Microsoft.VC80.CRT.manifest等。此错误发生的原因是在目标机器上需要这些文件的支持。

(按:实际上我只用到了Microsoft.VC80.CRT,Microsoft.VC80.MFC这两个目录里面的文件,和自己的程序打包放在一个目录下面即可)

3.
Added 1/15/2008

If you are confused by VS2005 which tells you cannot find some basic Afx functions, just add the following lines in your stdafx.h of your project

#include "C:\Program Files\Microsoft Visual Studio 8\VC\atlmfc\src\mfc\afximpl.h"

Then re-build, it could work

Of course the directory above depends where you installed your VS2005

Just my five cents



<< Home

This page is powered by Blogger. Isn't yours?