最近几天被这个问题困惑了许久。 不禁感叹微软的东东真是越做越烂了,也终于明白了时隔12年大家仍然死守VC6的原因。。


  用VC2005编译的程序,编译时没有任何错误,但是运行时就是提示“应用程序正常初始化失败”!! 查找了各方面资料,做了各种尝试,网上说什么的都有:有让安装vc2005 sp1补丁的;有让安装vcredist_x86.exe的; 有让把CRT库的dll直接拷贝到程序目录的; 有让清理注册表的;有让装.NetFramework新版本的;有让查manifest的;

  结果我尝试了半天,几乎都是浪费时间。上面最后一条说的还算正确,只是作者把事情描述得太繁琐了。。现在把处理的方法说一下,省得大家再走弯路:

  1. VC2003、VC2005、VC2008及其后续版本,对底层最基本的CRT、MFC、ATL库都进行了重构,为了避免不同版本的库引起冲突,重构后的库文件一般放在 C:\\windows\WinSxS 文件夹中,并用特定的文件夹\文件名称进行标识;

  2. 与VC6不同, VC2003、VC2005、VC2008及其后续版本,引入了manifest清单的概念,即应用程序编译后会同时生成对应的.manifest文件,并将该.manifest文件作为资源编译到dll或者exe中去。.manifest文件实际上是一个XML格式的文本文件,里面记录了dll或exe中要引用的CRT、MFC、ATL库的版本和名称。VC6编译的应用程序对CRT、MFC、ATL的dll都是直接调用,而VC2003、VC2005、VC2008编译的程序都是先查询编译到资源中的manifest中的记录,然后按照记录提供的版本和名称去搜寻对应的CRT、MFC、ATL库以及随库发布的.manifest文件,搜寻的路径包括当前目录、C:\\windows\WinSxS 等等,如果没有找到对应的库文件,则提示“应用程序正常初始化失败”;

  3.因此解决这个问题的办法就是:(a)用文本编辑器打开exe或dll对应的.manifest文件,查看它引用的CRT、MFC、ATL库的版本;或者,用UltraEdit直接打开exe或者dll,从资源区中找到编译进去的.manifest信息,找到它引用的CRT、MFC、ATL库的版本;或者,运行程序,当程序弹出“应用程序正常初始化失败”对话框时,在桌面上右键点击“我的电脑”-“管理”-“事件查看器”-“系统”,双击查看其中的记录,可以看到出错的原因是因为缺少了某某版本的CRT、MFC、ATL库,记录下这个版本信息;(b)记录到的库的版本信息一般类似于“Microsoft.VC90.DebugCRT”,之后到C:\\windows\WinSxS 或者VC200X的安装文件夹中搜索包含这个字符串的文件夹和文件,将搜索到的dll和.manifest文件都拷贝到应用程序所在的文件夹中,其中,.manifest文件必须重命名为“Microsoft.VC90.DebugCRT.manifest”(这里以Microsoft.VC90.DebugCRT为例),这样应用程序就可以正常运行了;(c)注意:库的.manifest文件和dll要一同拷贝到应用程序根目录去,因为应用程序会将编译到内部的manifest信息与外部的.manifest文件进行对比,之后才会对库的dll进行调用。如果只拷贝库的dll文件是没有用的;

  4.如果本机编译和运行程序都ok,但是将编译好的程序拿到其它机器上确无法运行,则多半也是这个原因。另外,如果提示"应用程序配置不正确",大多也是因为上面所说的CRT、MFC、ATL库版本与应用程序不匹配导致的,可以如法炮制进行解决;

在网上找出了这些方法:
  方法一:
  在类似C:\Program
Files\Microsoft Visual Studio 8\VC\redi
  st\Debug_NonRedist\x86\Microsoft.VC80.DebugCRT
下找到了下列文件:
  msvcm80d.dll
  msvcp80d.dll
  msvcr80d.dll
  Microsoft.VC80.DebugCRT.manifest
  把这几个文件拷贝到目标机器上,与运行程序同一文件夹或放到system32下,就可以正确运行了。
  其他release版、MFC程序什么的都是拷redist下相应文件夹下的文件就可以了,文件夹后都有标识!
  方法二:
  修改编译选项,将/MD或/MDd 改为 /MT或/MTd,这样就实现了对VC运行时库的静态链接,在运行时就不再需要VC的dll了。
  方法三:
  工程-》属性-》配置属性-》常规-》MFC的使用,选择“在静态库中使用mfc”
  这样生成的exe文件应该就可以在其他机器上跑了。
  方法四:
  你的vc8安装盘上找到再分发包vcredist_xxx.exe和你的程序捆绑安装
  在大部分机上都可以运行了,唯独在我的测试机上还是报应用程序配置错误。刚开始怀疑是还缺少dll,在能跑的机上把windows/system32目录下所有的msvc*.dll都复制到这台机的运行目录,还是不行!极度郁闷※×…!后来实在没辙了,就在VC环境中打开了EXE来查看它内嵌的manifest资源,无奈了看了一会,带着心中对manifest的咒骂,突然发现这个manifest带了两个版本CRT的依赖:
      再打开Microsoft.VC80.CRT.manifest一看,是这样:
    就是说,我们EXE的Manifest里多了一个版本依赖,那就把后面那个依赖删除试试。于是就把工程设置的生成manifest的选项去掉,手工改了一下manifest放到程序目录下,发现果然可以运行了!
  还有个问题没有明白,就是VC为什么在自傻膍anifest里带了两个依赖呢,上网再查了一下,发现在msdnonline上说'8.0.50608.0'这个版本是在XP下用的,'8.0.50727.762'这个版本是在Vista下用的(http://msdn.microsoft.com/en-us/library/ms235342(VS.80).aspx),可是我用的是'8.0.50727.762'在XP下运行的好好的!想不通是它错了还是别的原因。后来在CRT的源码里面搜索'8.0.50727.762',找到了~'8.0.50608.0'也在那里。
  #if defined
_USE_RTM_VERSION
  #define
_CRT_ASSEMBLY_VERSION “8.0.50608.0”
  #else
  #define _CRT_ASSEMBLY_VERSION
“8.0.50727.762”
  #endif
  显然默认的版本是“8.0.50727.762”,除非定义了_USE_RTM_VERSION!那为什么我们的工程会生成两个版本的依赖呢,明明这个地方是二选一的。一开始怀疑是工程设置引起的,我就把我们的工程拷出来,把里面的文件删掉,再复制一些向导生成的文件进来,编译一看,manifest里只有一个'8.0.50727.762',说明工程设置没有问题!最后我怀疑是工程链接的那些库的问题,因为有些库是用VC6或者VC2003编译的,但是有些库没有代码,编不了,没法尝试了。

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

2009-03-03 10:05

在使用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等。此错误发生的原因是在目标机器上需要这些文件的支持。

Visual C++
Libraries

Visual C++
Libraries as Shared Side-by-Side Assemblies

In Visual C++ 2005, the ATL, MFC, Standard C++, and
CRT libraries support the new deployment model available on Windows XP,
Windows Server 2003, and Windows Vista. The DLLs corresponding to all Visual
C++ libraries have been grouped into several shared side-by-side assemblies
and are installed into the native assembly cache, also called the WinSxS
folder, under the operating system root directory. Similarly, while building
a C++ application using Visual C++ 2005, by default the compiler and the
linker generate a manifest file that describes runtime dependencies of this
application on Visual C++ libraries.

Visual C++ libraries cannot be used by a C/C++
application without a manifest binding the application to these libraries. If
a C/C++ application that depends on a Visual C++ library does not use a
manifest, then an attempt to load the Visual C++ library as a dependent DLL
from the application-local folder will result in an error message indicating
that this is an unsupported way of loading a Visual C++ library.

Note:

On versions of Windows that do not support
deployment of shared side-by-side assemblies, such as Windows 98 and
Windows 2000 Server, the Visual C++ libraries are installed in the System32
folder and WinSxS folder under the operating system root directory. This
setup enables running Visual C++ applications on these operating system
versions because they do not support manifest-based binding of applications
to dependent DLLs. On these operating systems, when an application is
loaded, the corresponding manifest file is ignored and the operating systems
searches for dependent DLLs using paths set in the current running
environment. However, on upgrading the operating system to a version that
support manifest-based binding, such as Windows XP, Windows Server 2003, or
Windows Vista, applications built with manifests start using the DLLs
installed in the WinSxS folder.

This change to the deployment model of Visual C++
libraries prevents the problem of version conflicts between DLLs that occur
when you add updates or configurations to a machine, and will allow support
of side-by-side installation of two different Visual C++ toolsets. It will
also allow you to produce reliable, self-describing applications and
components that will not conflict with existing components. For more
information on the advantages of new deployment model, please see Concepts of Isolated Applications and Side-by-side
Assemblies
. To learn about how this may impact deployment of
existing native C++ applications, please refer to Redistributing Visual C++ Files.

Visual C++ libraries have been packaged in several
shared side-by-side assemblies with corresponding manifest files.

Assembly Name

DLLs included in the assembly

Visual C++ Library

Microsoft.VC90.ATL

atl90.dll

Active Template Library

Microsoft.VC90.CRT

msvcr90.dll

msvcp90.dll

msvcm90.dll

C Runtime Library, release DLLs

Microsoft.VC90.DebugCRT

msvcr90d.dll

msvcp90d.dll

msvcm90d.dll

C Runtime Library, debug DLLs

Microsoft.VC90.MFC

mfc90.dll

mfcm90.dll

mfc90u.dll

mfcm90u.dll

Microsoft Foundation Classes, release DLLs

Microsoft.VC90.DebugMFC

mfc90d.dll

mfcm90d.dll

mfc90ud.dll

mfcm90ud.dll

Microsoft Foundation Classes, debug DLLs

Microsoft.VC90.MFCLOC

mfc90chs.dll

mfc90deu.dll

mfc90esp.dll

mfc90ita.dll

mfc90kor.dll

mfc90cht.dll

mfc90enu.dll

mfc90fra.dll

mfc90jpn.dll

Microsoft Foundation Classes, localized resources

Microsoft.VC90.OpenMP

vcomp.dll

OpenMP Library, release DLLs

Microsoft.VC90.DebugOpenMP

Vcompd.dll

OpenMP Library, debug DLLs

http://wenku.baidu.com/link?url=lpOCsvRlBW_93VypbKoG9_IdQNvg59XNy2idhYOJ6RS9ohgSwJ_AytTCYsb8tered89-Sz3KBD6fjGU7y0UkP3zaq7EmD38lODzjQsvQZXK

[zz]VC2005-应用程序正常初始化失败-0xc0150002的更多相关文章

  1. 应用程序正常初始化(0xc0150002)失败的终极解决方案

    转自VC错误:http://www.vcerror.com/?p=62 最近做一个项目写了一个VC6下的MFC程序,结果传到别人的机子上(WIN7)出现了应用程序正常初始化(0xc0150002)失败 ...

  2. 应用程序无法正常启动0xc0150002 解决方式

        我也遇到过此问题,解决的方法: 方案一: 在项目的"属性|配置属性|链接器|常规"中的"启用增量链接"选择"否".此方法阻断了问题产 ...

  3. 解决应用程序无法正常启动0xc0150002问题(转)

    简述:使用VS2008写了一个MFC程序,结果传到别人的机子上(WIN7)出现应用程序正常初始化(0xc0150002)失败的问题.为什么我的机子上可以,而别人的机子上运行不了呢?下面是我找到的一个解 ...

  4. 应用程序正常初始化(0xc0000135)失败。请单击“确定”,终止应用程序。

    应用程序正常初始化(0xc0000135)失败.请单击“确定”,终止应用程序. 没有安装对应版本的.NET FRAMEWORK.

  5. NLPIR_Init文本分词-总是初始化失败,false,Init ICTCLAS failed!

    前段时间用这个分词用的好好的,突然间就总是初始化失败了: 网上搜了很多,但是不是我想要的答案,最终去了官网看了下:官网链接 发现哇,版本更新了啊,下载页面链接 麻利的下载好了最新的文档,一看压缩包名字 ...

  6. Quality Center11初始化失败

    打开start_a.jsp页面总是闪退,原因如下: 初始化失败因为证书签名过期了.把IE选项里证书检查的三项勾掉就好了(检查发行商的证书是否吊销.检查服务器证书吊销.检查已下载的程序的签名)

  7. spring 集成 mybatis 后数据源初始化失败问题分析

    问题背景: 项目使用spring,springmvc框架,后边需操作关系数据库,选择了mybatis + durid,集成mybatis后,项目一直启动失败.错误的原因是dataSource初始化的时 ...

  8. 应用程序无法正常启动0xc0150002(windows server 2003)

    windows server 2003运行一个程序时出现 "应用程序无法正常启动0xc0150002"的错误提示; 解决方案: 下载地址:http://www.microsoft. ...

  9. 项目 XXX 的 NuGet 程序包还原失败:找不到“xxx”版本的程序包“xxx”

    项目 XXX 的 NuGet 程序包还原失败:找不到“xxx”版本的程序包“xxx” 编译新下载的代码出错 修改包管理器的源为 http://www.nuget.org/api/v2/ .重试后成功 ...

随机推荐

  1. docker cgroup技术之cpu和cpuset

    在centos7的/sys/fs/cgroup下面可以看到与cpu相关的有cpu,cpuacct和cpuset 3个subsystem.cpu用于对cpu使用率的划分:cpuset用于设置cpu的亲和 ...

  2. 详解C#特性和反射(四)

    本篇内容是特性和反射的最后一篇内容,前面三篇文章: 详解C#特性和反射(一) 详解C#特性和反射(二) 详解C#特性和反射(三) 一.晚期绑定(Late Binding)是一种在编译时不知道类型及其成 ...

  3. 页面出现Incorrect string以及数据库内容乱码

    我在制作 (www.helpqy.com) 的时候遇到了页面报错Incorrect string的问题,我使用的是mysql,数据表中有很多中文内容,最后发现在安装mysql的时候需要选择defaul ...

  4. 分布式理论(六)—— Raft 算法

    前言 我们之前讲述了 Paxos 一致性算法,虽然楼主尝试用最简单的算法来阐述,但仍然还是有点绕.楼主最初怀疑自己太笨,后来才直到,该算法的晦涩难懂不是只有我一个人这么认为,而是国际公认! 所以 Pa ...

  5. Lightning Chart 8.4版新功能

    LightningChat V8.4版在如下功能上做了改进 边距 缩放功能 Legend box 的自动定位 正投影 相机orientation与rotation系统 全新3D 坐标空间转换器 Poi ...

  6. angular项目使用Swiper组件Loop时 ng-click点击事件失效处理方法

    在Angular项目中,使用swiper组件进行轮播展示时,存在将swper的loop设置为true时,部分页面的ng-click失效. 原因:将swiper中的looper设置为true时,为了视觉 ...

  7. IDEA Tomcat Web项目修改了代码,重新部署页面没改变

    今天被IDEA坑的不浅直接说一下问题: 这是html页面不管我怎么修改重启服务器在浏览器中还是一点都不变化,甚至把一些内容都删了都没有变化,target可执行文件是最新的没问题,找了点资料发现是浏览器 ...

  8. Tomcat9.0环境搭建与源码编译

    使用IntelliJ IDEA  搭建Tomcat9.0项目   准备条件:   下载源码 这里我们下载的Tomcat的源码版本是9.0.12. 下载地址: https://tomcat.apache ...

  9. ubuntu16.04安装ssh服务,并实现远程访问

    一.查看是否安装了ssh服务 apt-cache policy openssh-client openssh-server ubuntu默认安装了openssh-client,openssh-serv ...

  10. CentOS7部署Django项目

    1. 云服务器 这里使用的是腾讯云选择系统:CentOS7.3 记住云服务器登录密码 2. 配置Python3环境 默认Python环境为python2.7,yum安装是需要python2的环境的 安 ...