Windows 相关

来源:互联网 发布:美折促销软件 编辑:程序博客网 时间:2024/05/21 19:43

上位机兼容性

  • IDE: Visual Studio 2013 or Visual Studio Community 2017
  • Tools: eXeScope

问题说明: 上位机升级软件无法在 Windows XP 运行,运行提示为 不是有效的 WIN32 应用程序
不是有效的 WIN32 应用程序`

解决过程:eXeScope 查看 exe 信息
eXeScope 查看结果

要求系统主版本 6,查得对应的操作系统为 Windows Vista
List of Microsoft Windows versions

Name Release date Release version Windows 10 29 July 2015 NT 10.0 Windows 8.1 17 October 2013 NT 6.3 Windows 8 26 October 2012 NT 6.2 Windows 7 22 October 2009 NT 6.1 Windows Vista 30 January 2007 NT 6.0 Windows XP Professional x64 25 April 2005 NT 5.2 Windows XP 25 October 2001 NT 5.1 Windows ME 14 September 2000 4.90 Windows 2000 17 February 2000 NT 5.0 Windows 98 25 June 1998 4.10 Windows NT 4.0 24 August 1996 NT 4.0 Windows 95 24 August 1995 4.00

之后在 Visual Studio Community 2017 项目属性中作如下修改,使其对 Windows XP 兼容;
修改平台工具集

静态编译

  • 修改平台工具集: 使用兼容 XP 的工具链
  • 静态编译: 避免目标电脑缺少动态链接库,否则可能会提示 缺少 ***.dll;代价就是程序体积大一些,但对于简单的上位机软件来讲还是很方便,程序过大时可以考虑将程序和所缺失的DLL 一起打包安装到目标电脑。

之后运行仍然报错,提示 无法定位程序输入点 CoGetApartmentType 于动态链接库 ole32.dll
无法定位程序输入点 CoGetApartmentType 于动态链接库 ole32.dll

比较 Windows XPWindows 10ole32.dll,的确少了 CoGetApartmentType 函数
Windows XP ole32.dll

Windows 10 ole32.dll

Object Linking and Embedding(OLE): 允许开发者嵌入或链接 Windows 文件和对象;这样看来系统版本的差异在此体现出来,这种情况只能在源代码中跟踪 CoGetApartmentType 调用点,将其稍微做一下修改,不要使用该函数;一般而言 Windows 系统版本的不会影响到基础接口的功能,只会做一些辅助性功能的补充,所以基本上可以通过修改代码达到兼容性。

上位机接口函数

然后再回过头来看看 CoGetApartmentType 的作用,官网有如下两句话:

Returns the current apartment type and type qualifier
In multithreaded scenarios, there is a race condition which can potentially cause an Access Violation within the process when executing the above sequence of operations. The CoGetApartmentType function is recommended as it does not potentially incur the Access Violation

具体意思不太清楚,不管好像不是关键性函数。

结论猜测
- 如果不行,尝试升级到 Windows XP SP3
- COM(Component Object Model) 组件必须动态链接,这也许可以解释为什么静态编译不能将 Ole32.dllOLENUT32.dll 包括进去;(其实 kernel32.dll 也不行,有可能其作为系统的核心文件不允许这种操作)
- 如果上述方法还是解决不了,可以尝试让程序优先链接程序运行目录的 DLL(可行性尚不清楚,笔者未成功)