Windows manifest files are Win32 resources. In other words, they're embedded towards the end of the EXE or DLL. You can use LoadLibraryEx, FindResource, LoadResource and LockResource to load the embedded resource.
Here's a simple example that extracts its own manifest...
BOOL CALLBACK EnumResourceNameCallback(HMODULE hModule, LPCTSTR lpType,
LPWSTR lpName, LONG_PTR lParam)
{
HRSRC hResInfo = FindResource(hModule, lpName, lpType);
DWORD cbResource = SizeofResource(hModule, hResInfo);
HGLOBAL hResData = LoadResource(hModule, hResInfo);
const BYTE *pResource = (const BYTE *)LockResource(hResData);
TCHAR filename[MAX_PATH];
if (IS_INTRESOURCE(lpName))
_stprintf_s(filename, _T("#%d.manifest"), lpName);
else
_stprintf_s(filename, _T("%s.manifest"), lpName);
FILE *f = _tfopen(filename, _T("wb"));
fwrite(pResource, cbResource, 1, f);
fclose(f);
UnlockResource(hResData);
FreeResource(hResData);
return TRUE; // Keep going
}
int _tmain(int argc, _TCHAR* argv[])
{
const TCHAR *pszFileName = argv[0];
HMODULE hModule = LoadLibraryEx(pszFileName, NULL, LOAD_LIBRARY_AS_DATAFILE);
EnumResourceNames(hModule, RT_MANIFEST, EnumResourceNameCallback, NULL);
FreeLibrary(hModule);
return 0;
}
Alternatively, you can use MT.EXE from the Windows SDK:
>mt -inputresource:dll_with_manifest.dll;#1 -out:extracted.manifest
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…