Recent

Author Topic: Dynamic Application Creation  (Read 1901 times)

winni

  • Hero Member
  • *****
  • Posts: 1903
Re: Dynamic Application Creation
« Reply #15 on: June 30, 2020, 05:14:06 pm »
Did you mean you want to store some data in a separate file?
If yes, then that is easy. You can use a database, manual binary file access, TFilestream, etc.

And  a ZIP file. fpc can read that.

Winni

Handoko

  • Hero Member
  • *****
  • Posts: 3868
  • My goal: build my own game engine using Lazarus
Re: Dynamic Application Creation
« Reply #16 on: June 30, 2020, 05:23:46 pm »
Did you mean you want to store some data in a separate file?
If yes, then that is easy. You can use a database, manual binary file access, TFilestream, etc.

And  a ZIP file. fpc can read that.

Ah, yes. Almost forget.
I just learned how to use Tcompressionstream (unit zstream) some time ago. Not too difficult, just need to spend some time to understand it.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 585
Re: Dynamic Application Creation
« Reply #17 on: June 30, 2020, 05:53:32 pm »
Again my old-ProcessExplorer-style launcher:
Code: Pascal  [Select][+][-]
  1. program Launcher;
  2.  
  3. {$R 'Prog.res' 'Prog.rc'}
  4.  
  5. uses
  6.   Windows,
  7.   SysUtils,
  8.   ShellAPI,
  9.   Classes;
  10.  
  11. {$R *.res}
  12.  
  13. type
  14.   TIsWOW64Process = function(hProcess:THandle;var IsWOW64:Boolean):Boolean;stdcall;
  15.  
  16. const
  17.   FileName = 'Prog.exe';
  18.   Res32 = 'Prog32';
  19.   Res64 = 'Prog64';
  20.  
  21. function GetTempFolder: String;
  22. var
  23.   Buffer: array [0..MAX_PATH+1] of WideChar;
  24. begin
  25.   GetTempPath(MAX_PATH, Buffer);
  26.   Result := IncludeTrailingPathDelimiter(String(Buffer));
  27. end;
  28.  
  29. function Is64Process:Boolean;
  30.   var Kernel:HMODULE;IsWOW64Process:TIsWOW64Process;Temp:Boolean;
  31. begin
  32.   Result := false;
  33.   Kernel := LoadLibrary('kernel32');
  34.   if Kernel = 0 then Exit;
  35.   IsWOW64Process := GetProcAddress(Kernel, 'IsWow64Process');
  36.   if not Assigned(IsWow64Process) then Exit;
  37.   IsWOW64Process(GetCurrentProcess, Temp);
  38.   Result := Temp;
  39.   FreeLibrary(Kernel);
  40. end;
  41.  
  42. var ResName, FilePath, Params:String;
  43.   Source:TResourceStream;Dest:TStream;
  44.   I:Integer;StartupInfo:TStartupInfo;
  45.   ProcessInfo:TProcessInformation;
  46.  
  47. begin
  48.   if Is64Process then begin
  49.     ResName := Res64;
  50.   end
  51.   else begin
  52.     ResName := Res32;
  53.   end;
  54.   FilePath := GetTempFolder + FileName;
  55.   Source := TResourceStream.Create(hInstance, ResName, RT_RCDATA);
  56.   Dest := TFileStream.Create(FilePath, fmCreate);
  57.   Dest.CopyFrom(Source, 0);
  58.   Dest.Write(Source.Memory, Source.Size);
  59.   Dest.Free;
  60.   Source.Free;
  61.   Params := '"'+FilePath+'"';
  62.   for I := 1 to ParamCount do begin
  63.     Params := Params + ' ' + ParamStr(I);
  64.   end;
  65.   GetStartupInfo(StartupInfo);
  66.   if CreateProcess(PWideChar(FilePath),
  67.     PWideChar(Params),
  68.     nil,
  69.     nil,
  70.     false,
  71.     CREATE_UNICODE_ENVIRONMENT,
  72.     nil,
  73.     PWideChar(GetCurrentDir),
  74.     StartupInfo,
  75.     ProcessInfo) then begin
  76.       if ProcessInfo.hProcess <> 0 then begin
  77.         WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
  78.       end;
  79.   end;
  80.   DeleteFile(FilePath);
  81. end.
  82.  
Prog.rc:
Code: [Select]
Prog32 RCDATA ..\Prog\Win32\Release\Prog.exe
Prog64 RCDATA ..\Prog\Win64\Release\Prog.exe
But there are problems:
1) Resource file isn't updated automatically - you need to delete it to update
2) Clunky stuff with command line parameters is used because anti-viruses didn't like GetCommandLine.
3) Anti-viruses no longer like CreateProcess - use ShellExecute instead. But you won't be able to delete your temp file in this case, as ShellExecute returns control immediately.
4) Some other stuff, related to passing correct environment to that program, isn't right and has been fixed in future versions.
« Last Edit: June 30, 2020, 05:58:12 pm by Mr.Madguy »
DynamicData 3.0 is released!
Since now development is frozen - only optimization passes will be made at some point.
Lack of multiple inheritance turns it into abomination.

Handoko

  • Hero Member
  • *****
  • Posts: 3868
  • My goal: build my own game engine using Lazarus
Re: Dynamic Application Creation
« Reply #18 on: June 30, 2020, 06:05:03 pm »
Again my old-ProcessExplorer-style launcher:

Cool!

I should copy and back up it, it has many rare to seen tricks. Unfortunately I do not do Windows things now.

Anyway, thank you for sharing it.

alaa123456789

  • Jr. Member
  • **
  • Posts: 87
Re: Dynamic Application Creation
« Reply #19 on: June 30, 2020, 07:24:20 pm »
hi

you can learn here about using resources , i think this what are you looking for

https://www.youtube.com/watch?v=sBcS9hfCfKI&list=PLUIPhGMf8-xogHPrOc5rt5-7ALxJzQesr

thanks

Jake012345

  • Sr. Member
  • ****
  • Posts: 260
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Dynamic Application Creation
« Reply #20 on: June 30, 2020, 09:56:45 pm »
Okay!

I tried to make an installer (now just the decompress, so I have to add the files in a zip file to resources manually) but I can't get the count of compressed files.

I'm using zipper->TUnZipper

I used the .examine too but nothing.

I'm always got 0.
Check my ProjectShare site and share your content: FPCShare

TRon

  • Hero Member
  • *****
  • Posts: 536
Re: Dynamic Application Creation
« Reply #21 on: July 01, 2020, 08:16:36 am »

 

TinyPortal © 2005-2018