Bartosz Jarzyna
Bartosz Jarzyna

Reputation: 13

Corrupted winapi executable manifest

I am developing a Qt application working with XML files. To increase performance, I'm using the pugixml parser instead of Qt's dom parser. 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.

Everything was working fine until I needed to replace QString::toStdString() with QString::toStdWString(). The reason for that is reading files with extended letters in names (ąęśćłóźżń) into pugixml. I run pugixml::document::load_file() with data loaded previously by a Qt recursive directory loop. QStrings which contain filenames are converted to std::wstring and then to const wchar_t* with qstring.toStdWString().c_str().

After replacing strings with wstrings, the unpacked executable was working well. However, after packing it, the final .exe file has a corrupted manifest that looks like this:

<?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. The makefile of the final package looks like this:

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).

Upvotes: 0

Views: 123

Answers (1)

Bartosz Jarzyna
Bartosz Jarzyna

Reputation: 13

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. I'll describe the procedure for future reference.

Create a new manifest.rc file, which looks like this:

#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.o: manifest.rc
    windres manifest.rc manifest.o

Don't forget to add manifest.o to main program recipe in the Makefile:

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

Upvotes: 0

Related Questions