Page 1 of 1

[madRes] Update Exe Resources

PostPosted: Sun Mar 27, 2005 9:38 am
by Lamez
Hi! I wrote this code but it doesn't working. :? Where is the problem?
Code: Select all
procedure UpdateRes(exeFile, ResName, resFile: string);
var
  resUpdateHandle : dword;
  resMem : TFileStream;
begin
  resUpdateHandle := BeginUpdateResourceW(PWideChar(wideString(exeFile)), false);
  resMem := TFileStream.Create(resFile, fmOpenRead);
  if resUpdateHandle <> 0 then
    begin
      UpdateResourceW(resUpdateHandle, WideChar(RT_RCDATA), PWideChar(PChar(ResName)), 1045,  @resmem, resmem.Size);
      EndUpdateResourceW(resUpdateHandle, false);
      resMem.Free;
    end;
end;

PostPosted: Tue Mar 29, 2005 8:18 am
by madshi
You can't use "@resMem" like that. Using "@resMem" doesn't give you the content of the file, but the content of the TFileStream object instance.

PostPosted: Tue Mar 29, 2005 11:39 am
by Lamez
Can I use resmem.Memory?

PostPosted: Tue Mar 29, 2005 11:50 am
by madshi
Not when using a TFileStream. You could use TMemoryStream instead and then use "LoadFromFile". Afterwards you can use "TMemoryStream.Memory^".

PostPosted: Fri Apr 08, 2005 11:52 am
by Lamez
It's OK?
Code: Select all
procedure UpdateRes(exeFile, ResName, resFile: string);
var
  resHandle : dword;
  resMem : TMemoryStream;
begin
  resHandle := BeginUpdateResourceW(PWideChar(wideString(exeFile)), false);
  try
    resMem := TMemoryStream.Create;
    resMem.LoadFromFile(ResFile);
  if resHandle <> 0 then
    begin
      UpdateResourceW(resHandle, PWideChar(RT_RCDATA), PWideChar(WideString(ResName)), 1045,  resmem.Memory, resmem.Size);
      EndUpdateResourceW(resHandle, False);
    end;
  finally
    resMem.Free;
  end;
end;

PostPosted: Fri Apr 08, 2005 12:35 pm
by madshi
Looks alright to me.

PostPosted: Fri Apr 08, 2005 4:24 pm
by Lamez
But not working... :o

PostPosted: Fri Apr 08, 2005 4:37 pm
by madshi
That's not a very detailed error description. Could you please be a bit more specific?

PostPosted: Fri Mar 31, 2006 3:58 pm
by Kendy
Code: Select all
procedure UpdateRes(exeFile, ResName, resFile: string);
var
  resHandle : dword;
  resMem : TMemoryStream;
begin
  resHandle := BeginUpdateResourceW(PWideChar(wideString(exeFile)), false);
  //try   <<<
    resMem := TMemoryStream.Create;
    try   //<<<
    resMem.LoadFromFile(ResFile);
  if resHandle <> 0 then
    begin
      UpdateResourceW(resHandle, PWideChar(RT_RCDATA), PWideChar(WideString(ResName)), 1045,  resmem.Memory, resmem.Size);
      EndUpdateResourceW(resHandle, False);
    end;
  finally
    resMem.Free;
  end;
end;


I use it OK,My OS is WinXpSp2.