Forum > General

Create file (exe) from resource (fail) ?

(1/1)

seba22:
Welcome,


I want attach updater application inside my exe file.

Using lazres i had created file called program.lrs.

Next i add that procedure.



--- Code: ---procedure SaveResourceAsFile(const ResName: string; ResType: pchar;
  const FileName: string);
begin
  with TResourceStream.Create(hInstance, ResName, ResType) do
    try
      SaveToFile(FileName);
    finally
      Free;
    end;
end;   
--- End code ---

Next step was, on bottom Unit1.pas add


--- Code: ---initialization
{$I program.lrs}
--- End code ---


Next (for example) in on create form event add


--- Code: ---procedure TForm1.FormCreate(Sender: TObject);
begin
  SaveResourceAsFile('myexe','EXE','c:\test.exe');
end;
--- End code ---

And that's header of program.lrs


--- Code: ---LazarusResources.Add('myexe','EXE',[     
--- End code ---


Application compile but after load... i got error "myexe" resource not found...

Ocye:
I run into same problem. Resource has been built without error, program works but does not find the executable. All other stuff (cur, wav, bmp) can be load from resource. Maybe there is a bug in FindResource() or in lazres.
I'm wondering why size increased from ~180k (xy.exe) to ~500k (xy.res) after resourceifying...

seba22:
I have override my problem... right now i'm downloading file from internet using indy :/
It was faster than fun with resources...


It's normal that size of res file increase, it have to be encoded.
I don't know what encoding use Lazarus... it can be even base64.


If anyone find idea how create external file using resources... feel free to post !

LazaruX:
I haven't tried with EXE's, but it works fine for me with images.
I haven't got the code by hand now, and I may suggest you a stupid thing, but please try to change this (remove the .exe extension)

--- Code: ---SaveResourceAsFile('myexe','EXE','c:\test');

--- End code ---

Hope this works

Navigation

[0] Message Index

Go to full version