Recent

Author Topic: Create file (exe) from resource (fail) ?  (Read 7706 times)

seba22

  • Full Member
  • ***
  • Posts: 136
Create file (exe) from resource (fail) ?
« on: March 09, 2010, 07:24:48 pm »
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: [Select]
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;   

Next step was, on bottom Unit1.pas add

Code: [Select]
initialization
{$I program.lrs}


Next (for example) in on create form event add

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
begin
  SaveResourceAsFile('myexe','EXE','c:\test.exe');
end;

And that's header of program.lrs

Code: [Select]
LazarusResources.Add('myexe','EXE',[     

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

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Create file (exe) from resource (fail) ?
« Reply #1 on: March 19, 2010, 05:52:09 am »
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...
« Last Edit: March 19, 2010, 06:29:28 am by Ocye »
Lazarus 1.7 (SVN) FPC 3.0.0

seba22

  • Full Member
  • ***
  • Posts: 136
Re: Create file (exe) from resource (fail) ?
« Reply #2 on: March 19, 2010, 10:49:31 am »
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

  • Hero Member
  • *****
  • Posts: 597
  • Lazarus original cheetah.The cheetah doesn't cheat
Re: Create file (exe) from resource (fail) ?
« Reply #3 on: March 19, 2010, 05:15:28 pm »
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: [Select]
SaveResourceAsFile('myexe','EXE','c:\test');

Hope this works

 

TinyPortal © 2005-2018