Embeding application manifests into Windows executables as a resource

If your Win32 application needs to declare that is supports something before it even executes, this is where a manifest file comes in. While you can ship one with your application (in the form of appname.exe.manifest), it’s more fool-proof to just embed it into your application. You can do so with

The simple way is to specify a resource of ID 1 (use 2 for DLLs), type RT_MANIFEST, and you can simply embed the the file by specifying its name:

1 RT_MANIFEST "appname.exe.manifest"

If your toolchain doesn’t support RT_MANIFEST (i.e: it’s old), then specify resource type 24. It might be a good idea to do an #ifdef, something like:

#ifndef RT_MANIFEST
#define RT_MANIFEST 24
#endif

The manifest I tend to use enables themes on common controls and enables modern DPI awareness. This is it below:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
	<assemblyIdentity
		version="1.0.0.0"
		processorArchitecture="*"
		name="App.Assembly"
		type="win32"
	/>
	<description>App Name</description>
	<asmv3:application>
		<asmv3:windowsSettings>
			<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
			<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
		</asmv3:windowsSettings>
	</asmv3:application>
	<dependency>
		<dependentAssembly>
			<assemblyIdentity
				type="win32"
				name="Microsoft.Windows.Common-Controls"
				version="6.0.0.0"
				processorArchitecture="*"
				publicKeyToken="6595b64144ccf1df"
				language="*"
			/>
		</dependentAssembly>
	</dependency>
</assembly>

This works even if you’re using something like VC++6. For simple applications that just use dialog boxes, for example, Windows 10 will automatically scale the dialog to the appropriate DPI for you.

Leave a Reply

Your email address will not be published.