NO

Author Topic: AddResManifest, tool for insert simple manifest to exe  (Read 2807 times)

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2107
AddResManifest, tool for insert simple manifest to exe
« on: November 19, 2016, 12:13:43 PM »
AddResManifest is a tool for inserting simple manifest to exe  from resource.

This version is just for GUI and ComCtrl32 version 6 manifest.

Modify project resource your own purposes.

Basic code is simple:
Code: [Select]
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commdlg.h>
#pragma comment(lib, "comdlg32.lib")

OPENFILENAME ofn;
TCHAR szFilter[] = TEXT("Program (*.exe)\0*.exe\0\0");
TCHAR szFileName[MAX_PATH];

void __cdecl WinMainCRTStartup(void)
{
TCHAR *lpszCmdLine, *pChar;

lpszCmdLine = GetCommandLine();
pChar = lpszCmdLine;
if (*pChar == '"') {
pChar++;
while (*pChar && *pChar != '"')
pChar++;
pChar++;
} else {
while (*pChar && *pChar != ' ')
pChar++;
}
while (*pChar && *pChar <= ' ')
pChar++;

if (!*pChar) {
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn))
pChar = szFileName;
}
if (*pChar)
{
HMODULE hModule = GetModuleHandle(NULL);
HRSRC resrc = FindResource(hModule, MAKEINTRESOURCE(1), RT_MANIFEST);
if (resrc)
{
int cbData = SizeofResource(hModule, resrc);
LPVOID pDataRes = LockResource(LoadResource(hModule, resrc));
HANDLE hRes = BeginUpdateResource(pChar, FALSE);
if (hRes)
{
if (UpdateResource(hRes, RT_MANIFEST, MAKEINTRESOURCE(1), 1033, pDataRes, cbData))
{
EndUpdateResource(hRes, FALSE);
MessageBox(0, TEXT("Manifest updated"), 0, MB_OK);
} else EndUpdateResource(hRes, TRUE);
} else MessageBox(0, TEXT("File not found ?"), 0, MB_OK);
}
} else MessageBox(0, TEXT("Empty commandline"), 0, MB_OK);
ExitProcess(0);
}
« Last Edit: November 26, 2016, 11:21:50 AM by TimoVJL »
May the source be with you