要将清单添加到应用程序,您需要创建一个 MyApp.manifest 文件并将其添加到应用程序资源文件:
//-- This define is normally part of the SDK but define it if this
//-- is an older version of the SDK.
#ifndef RT_MANIFEST
#define RT_MANIFEST 24
#endif
//-- Add the MyApp XP Manifest file
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "MyApp.manifest"
对于较新版本的Visual Studio,项目设置中有一个Manifest Tool选项卡,此选项卡上的Additional Manifest Files字段也可用于定义清单文件。
这是一个 Win32 应用程序的简单 MyApp.manifest 文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.1"
processorArchitecture="X86"
name="Microsoft.Windows.MyApp"
type="win32"
/>
<description>MyApp</description>
</assembly>
如果您的应用程序依赖于其他 dll,这些详细信息也可以添加到清单中,Windows 将使用此信息来确保您的应用程序始终使用这些依赖 dll 的正确版本。
例如,这里是通用控件和 8.0 版 C 运行时库的清单依赖项详细信息:
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.VC80.CRT"
version="8.0.50608.0"
processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b" />
</dependentAssembly>