简体   繁体   English

Winapi可执行清单损坏

[英]Corrupted winapi executable manifest

I am developing a Qt application working with XML files. 我正在开发使用XML文件的Qt应用程序。 To increase performance, I'm using the pugixml parser instead of Qt's dom parser. 为了提高性能,我使用的是pugixml解析器,而不是Qt的dom解析器。 After compiling, my application and all dependencies (dll files, helper programs) are packed as a resource of a winapi application to create a single exe file. 编译后,我的应用程序和所有依赖项(dll文件,帮助程序)都打包为winapi应用程序的资源,以创建单个exe文件。

Everything was working fine until I needed to replace QString::toStdString() with QString::toStdWString() . 一切工作正常,直到需要用QString::toStdString()替换QString::toStdString() QString::toStdWString() The reason for that is reading files with extended letters in names ( ąęśćłóźżń ) into pugixml. 这样做的原因是将名称中带有扩展字母( ąęśćłóźżń )的文件读入pugixml。 I run pugixml::document::load_file() with data loaded previously by a Qt recursive directory loop. 我运行pugixml::document::load_file()并使用Qt递归目录循环先前加载的数据。 QString s which contain filenames are converted to std::wstring and then to const wchar_t* with qstring.toStdWString().c_str() . 包含文件名的QString转换为std::wstring ,然后使用qstring.toStdWString().c_str()转换为const wchar_t*

After replacing string s with wstring s, the unpacked executable was working well. wstring替换string之后,解压缩的可执行文件运行良好。 However, after packing it, the final .exe file has a corrupted manifest that looks like this: 但是,打包后,最终的.exe文件具有损坏的清单,如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!--The ID below indicates application support for Windows Vista -->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
      <!--The ID below indicates below indicates application support for Windows
 7 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <!--The ID below indicates application support for Windows 8 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
      <!--The ID below indicates application support for Windows 8.1 -->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <!--The ID below indicates application support for Windows 10 -->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
    </application>
  </compatibili

I am using Windows 7 64bit, compiling with MinGw -w64 shell. 我正在使用Windows 7 64bit,并使用MinGw -w64 shell进行编译。 The makefile of the final package looks like this: 最终软件包的makefile如下所示:

all: final.exe

final.exe: sad.o res.o
    g++ -o final.exe -static-libgcc sad.o res.o resource.o -lcomctl32 -lshlwapi -mwindows

sad.o: sad.cpp
    g++ -c sad.cpp

res.o: sad.rc resource.h resource.cpp
    windres sad.rc res.o
    g++ -c resource.cpp

clean:
    rm -f *o final.exe

( res.o contains the program and all dependencies packed by windres, sad.cpp contains the winapi program that calls my application from resource). res.o包含该程序以及windres打包的所有依赖项, sad.cpp包含从资源调用我的应用程序的winapi程序)。

Not sure what caused the issue, seems like compiler fault, however it can be worked around by creating winapi resource out of xml file containing a valid manifest. 不知道是什么原因引起的,似乎是编译器错误,但是可以通过从包含有效清单的xml文件中创建winapi资源来解决。 I'll describe the procedure for future reference. 我将描述该过程以供将来参考。

Create a new manifest.rc file, which looks like this: 创建一个新的manifest.rc文件,如下所示:

#include <windows.h>
RT_MANIFEST BINARY  MOVEABLE PURE "manifest.xml"

Then create a manifest.xml file containing a valid manifest XML file and add to Makefile: 然后创建一个包含有效清单文件的manifest.xml文件,并添加到Makefile中:

manifest.o: manifest.rc
    windres manifest.rc manifest.o

Don't forget to add manifest.o to main program recipe in the Makefile: 不要忘记在manifestfile中将manifest.o添加到主程序配方中:

final.exe: sad.o res.o manifest.o
    g++ -o final.exe -static-libgcc sad.o res.o resource.o manifest.o -lcomctl32 -lshlwapi -mwindows

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM