[madRes] Update Exe Resources

delphi package - madRes, madTools, madStrings, ...

[madRes] Update Exe Resources

Postby Lamez » Sun Mar 27, 2005 9:38 am

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

Postby madshi » Tue Mar 29, 2005 8:18 am

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

Postby Lamez » Tue Mar 29, 2005 11:39 am

Can I use resmem.Memory?
Lamez
 
Posts: 4
Joined: Sun Mar 27, 2005 9:31 am

Postby madshi » Tue Mar 29, 2005 11:50 am

Not when using a TFileStream. You could use TMemoryStream instead and then use "LoadFromFile". Afterwards you can use "TMemoryStream.Memory^".
madshi
Site Admin
 
Posts: 9411
Joined: Sun Mar 21, 2004 5:25 pm

Postby Lamez » Fri Apr 08, 2005 11:52 am

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

Postby madshi » Fri Apr 08, 2005 12:35 pm

Looks alright to me.
madshi
Site Admin
 
Posts: 9411
Joined: Sun Mar 21, 2004 5:25 pm

Postby Lamez » Fri Apr 08, 2005 4:24 pm

But not working... :o
Lamez
 
Posts: 4
Joined: Sun Mar 27, 2005 9:31 am

Postby madshi » Fri Apr 08, 2005 4:37 pm

That's not a very detailed error description. Could you please be a bit more specific?
madshi
Site Admin
 
Posts: 9411
Joined: Sun Mar 21, 2004 5:25 pm

Postby Kendy » Fri Mar 31, 2006 3:58 pm

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.
Kendy
 
Posts: 5
Joined: Wed Mar 29, 2006 11:42 am


Return to madBasic

Who is online

Users browsing this forum: No registered users and 1 guest