[madRes] Update Exe Resources

delphi package - madRes, madTools, madStrings, ...
Post Reply
Lamez
Posts: 4
Joined: Sun Mar 27, 2005 9:31 am

[madRes] Update Exe Resources

Post 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;
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post 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.
Lamez
Posts: 4
Joined: Sun Mar 27, 2005 9:31 am

Post by Lamez »

Can I use resmem.Memory?
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Not when using a TFileStream. You could use TMemoryStream instead and then use "LoadFromFile". Afterwards you can use "TMemoryStream.Memory^".
Lamez
Posts: 4
Joined: Sun Mar 27, 2005 9:31 am

Post 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;
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Looks alright to me.
Lamez
Posts: 4
Joined: Sun Mar 27, 2005 9:31 am

Post by Lamez »

But not working... :o
madshi
Site Admin
Posts: 10339
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

That's not a very detailed error description. Could you please be a bit more specific?
Kendy
Posts: 5
Joined: Wed Mar 29, 2006 11:42 am

Post 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.
Post Reply