We help IT Professionals succeed at work.

Problem while trying to add XP manifest to a compiled exe

Marc582
Marc582 asked
on
Hi,

I want to add XP manifest to a compiled exe,

I'm using this code:

-----------------------------------------------------------
function ReadFilePoke(FileName: string): widestring;
var
  F:      file;
  Buffer: widestring;
  Size:   integer;
  ReadBytes: integer;
  DefaultFileMode: byte;
begin
  Result := '';

  DefaultFileMode := FileMode;

  FileMode := 0;
  AssignFile(F, FileName);
  Reset(F, 1);

  if (IOResult = 0) then
  begin
    Size := FileSize(F);

    while (Size > 1024) do
    begin
      SetLength(Buffer, 1024);
      BlockRead(F, Buffer[1], 1024, ReadBytes);
      Result := Result + Buffer;
      Dec(Size, ReadBytes);
    end;

    SetLength(Buffer, Size);
    BlockRead(F, Buffer[1], Size);
    Result := Result + Buffer;

    CloseFile(F);
  end;

  FileMode := DefaultFileMode;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
buffer: widestring;
update : dword;
begin

  buffer := readfilepoke('C:\man.txt');
   update := BeginUpdateResource('C:\man.exe', false);
  if update <> 0 then
    try
      UpdateResource(update, MAKEINTRESOURCE(24), '1', 0, @buffer[1], length(buffer));
    finally
      EndUpdateResource(update, false);
    end;

end;
-----------------------------------------------------------

man.exe is the file without manifest,
man.txt is my file containing manifest:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <assemblyIdentity
      name="Microsoft.Windows.MyCoolApp"
      processorArchitecture="x86"
      version="5.1.2600.0"
      type="win32"/>
   <description>Application description here</description>
   <dependency>
      <dependentAssembly>
         <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="x86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
         />
      </dependentAssembly>
   </dependency>
</assembly>




when I check with a resource editor, everything seems fine!
even if for example, I remove the manifest of calc.exe, then add it again (the exact manifest) with my code, when I compare both file using resource editor, it's the samething! i cant see any difference, but when I execute both, one has the xp look, and the other one doesn't,

I really don't understand!


NOTE that I don't want to add manifest on my own project, I already know how, what I want to do is to be able to add manifest on any already compiled exe


thx in advance!

500 points for this

Comment
Watch Question

Top Expert 2007
Commented:
you're incorrectly using "1" there as the name. you should be using MAKEINTRESOURCE(1)
also make sure you are using the correct language for your system locale.
and I don't understand why you are using widestring as a buffer. the XML is ascii. the encoding of the values from it are UTF-8.
I have to run for a few hours, but if yuo cannot fix it, I'll make a demo for you.

Author

Commented:
thx!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.