天天看点

应用程序无法启动 因为应用程序的并行配置不正确 debug抗争史

问题来源:一个早期vc或者vs studio编写的工程,在我的vs2012(win8)下升级+编译后,运行失败,提示:

 应用程序无法启动,因为应用程序的并行配置不正确。有关详细信息,请参阅应用程序事件日志,或使用命令行 sxstrace.exe 工具

百度一下sxstrace用法:

stdafx.hstdafx.h是vc创建工程时自动生成的头文件,里面的内容一般是再包含其他的头文件

1)  管理员运行cmd ,SxsTrace Trace -logfile:SxsTrace.etl,启动跟踪;

2) 执行目标程序,在弹出错误对话框后;

3) 回到cmd命令行,按回车键,然后输入执行命令:SxsTrace Parse -logfile:SxsTrace.etl -outfile:SxsTrace.txt

先是win8下管理员运行cmd   使用win+x组合键,选择命令提示符(管理员)

为了判定sxstrace.txt的位置,我决定去执行程序的目录下,执行相应的命令

cd 命令转换目录不成功,解决方案如下:

 例如cd F: 后还在c盘,使用如下命令: F:  回车或者 cd /d F:/

sxsTrace 确实在exe程序同一个文件夹下,打开后主要错误如下:

INFO: Manifest Definition Identity is (null).

ERROR: Line 11: XML Syntax error.

如果这里提示的是缺少什么运行库就好了,哎

然后带着这两条错误google,在外国的一个论坛上找到了类似的错误

试着去解决:

这种情况是因为manifest中储存各种程序指定dll的入口,如果找不到这些dll,主要是CRT,就会提示上述错误

manifest要么位于appname.exe.manifest文件,要么在二进制可执行程序中,我没发现这个文件

那么就在二进制文件中,于是用nodepad++ 打开exe

(ps:需要安装插件HexEditor,然后view in hex)

manifest, 在二进制文件的结尾部分,当看到xml文件的时候

应用程序无法启动 因为应用程序的并行配置不正确 debug抗争史

就找到了,然后根据找到依赖项:

应用程序无法启动 因为应用程序的并行配置不正确 debug抗争史

micsoft.windows.common-controls, 在c:/windows/winsxs                     (winsxs   是side-by-side,并行环境的意思 )

外国友人是因为vc90_crt版本不对,下载安装就ok,教程结束,然而我这里却不行

目录下搜索micsoft.windows.common-controls 发现有很多,那大概是版本不对,然后继续搜索,在msdn上找到了一段代码来测试相应的版本

#include <cstdio>
#include <windowsx.h>
#include <tchar.h>
#include <iostream>
#include "windows.h"
#include "windef.h"
#include "winbase.h"
#include "shlwapi.h"
#include <StrSafe.h>

#define PACKVERSION(major,minor) MAKELONG(minor,major)
using namespace std;

DWORD GetVersion(LPCTSTR lpszDllName)
{
	HINSTANCE hinstDll;
	DWORD dwVersion = 0;

	// For security purposes, LoadLibrary should be provided with a fully qualified 
	// path to the DLL. The lpszDllName variable should be tested to ensure that it 
	// is a fully qualified path before it is used. 
	hinstDll = LoadLibrary(lpszDllName);
	
	if(hinstDll)
	{
		DLLGETVERSIONPROC pDllGetVersion;
		pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hinstDll, "DllGetVersion");

		// Because some DLLs might not implement this function, you must test for 
		// it explicitly. Depending on the particular DLL, the lack of a DllGetVersion 
		// function can be a useful indicator of the version. 

		if(pDllGetVersion)
		{
			DLLVERSIONINFO dvi;
			HRESULT hr;

			ZeroMemory(&dvi, sizeof(dvi));
		   // dvi.info1.cbSize = sizeof(dvi);
			dvi.cbSize=sizeof(dvi);
			hr = (*pDllGetVersion)(&dvi);

			if(SUCCEEDED(hr))
			{
			   //dwVersion = PACKVERSION(dvi.info1.dwMajorVersion, dvi.info1.dwMinorVersion);
				dwVersion=PACKVERSION(dvi.dwMajorVersion,dvi.dwMinorVersion);
			}
		}
		FreeLibrary(hinstDll);
	}
	return dwVersion;
}

int main(){

LPCTSTR lpszDllName = L"C:\\Windows\\System32\\ComCtl32.dll";
DWORD dwVer = GetVersion(lpszDllName);
DWORD dwTarget = PACKVERSION(6,0);

if(dwVer >= dwTarget)
{
	cout<<"hello "<<dwTarget <<endl;
}
else
{
	
	//cout<<"what's new "<<dwTarget <<" " <<dwVer<<endl;
	cout<< ((dwTarget & 0xFFFF0000)>>16) <<" "<<(dwTarget & 0x0000FFFF)<<endl;
	cout<< ((dwVer & 0xFFFF0000)>>16) <<" "<<(dwVer & 0x0000FFFF)<<endl;
	// Proceed knowing that version 6.0 or later additions are not available.
	// Use an alternate approach for older the DLL version.
}

return 0;
}
           

结果发现小于6.0,我想试试能不能通过修改二进制文件的xml把版本改成自己的,需要解析DWORD 变量 dwVer的含义,就是明白packversion这个函数怎么把6,0变成了一个该类型变量,百度makelong的含义,是把第二个参数16位变量左移16位加上第一个参数构成一个32位变量,于是进行一些位运算还原就是了,然后得到5 82,那么我的版本是5.82,然后继续在winsxs下搜索,找到

应用程序无法启动 因为应用程序的并行配置不正确 debug抗争史

版本号全称5.82.9200.20765  然后pub key 是红框里的一串字符

(ps:通过找几个数字的二进制吗来判断在何处修改)

修改后,但是没有作用,难道注定要安装micsoft.windows.common-controls 6.0?

等学点windows编程再来回头看看吧

继续阅读