Recent

Author Topic: [SOLVED] My Own 'IDE' --> Create My Own EXE's  (Read 16159 times)

derek.john.evans

  • Guest
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #15 on: August 20, 2016, 12:51:46 pm »
Hi technipixel

Fungus has a good idea/point (back a couple of posts).

I haven't tried it, but fungus is recommending placing your data at the end of your reader exe. The last 4 bytes of the exe will be the start location of your data. If that works on linux/windows, then, yes, I think thats better than Win32 resources.

So, you would create a reader which will compile for Windows/Linux/Mac.

You would then have the 3 exe's with your IDE. Depending on the target the user selects, you would load the exe, copy the data to the end with the start pos of the data.

Each reader would then look for this value in itself. ie: ParamStr(0)

Personally, I don't know why you want the book + exe together. Would'nt it be better to have a library of books accessed by the one exe?

Or, do you want somekinda protection? In which case, why not just Blowfish the book and make it available via HTTP? So, they download a reader. The reader shows the books available. and if they have a password, they can read them.

Im just guessing, since you haven't explained why you want to release a book that compresses to a few hundred kb released with a 1.7M+ exe

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #16 on: August 20, 2016, 12:54:56 pm »
I'm not sure if I understand your project right, but to me it seems like you are turning something simple into something difficult. Think of a self-extracting archive - it is an executable that has an archive "slip streamed" to the end of it. When you execute it, it will read a 32/64 bit numeric value from the end of itself and this value can then be used to determine the offset in the file where the executable ends and the archive begins. From there it can extract its contents.

If you would create an executable that is used to display a book you would simply create an app that has the functionality of displaying the book. Then you would take the book itself and combine both into one file - just like a self-extracting archive. When your book-reader is then executed it will load the book from the executable file - simple and easy. Absolutely no need for performing a per-book compilation of some source code. Consider this to combine an executable and a document:

And from there the book can be displayed by the app :-)

Well, basically that is what I am saying.
I'm not creating an eBook within LAZ....

- I create IDE using LAZ
- Distribute my IDE app
- User creates Resource (as their project) file with my IDE
- Then the user embeds ("saves") resource into existing EXE to create their own app.

I don't want to create something like LAZ.
And I am not talking about creating a Resource file within LAZ

I want to do all this problematically within my own app (made with LAZ)

I did this same thing using VB.NET in two ways. (these are my posts on VBForums)

1) Created a template EXE with functions to read external resource file...
http://www.vbforums.com/showthread.php?833359-Simple-Write-Read-External-Resource-File

2) Using CodeDom to actually compile VB code (including external files (using Resource code))
http://www.vbforums.com/showthread.php?833333-RESOLVED-CodeDom-Save-Load-RTF-Into-RichBox

So, the code example you gave, it seems to be missing some parts.
Do you have a complete example on this I could see?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Fungus

  • Sr. Member
  • ****
  • Posts: 354
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #17 on: August 20, 2016, 01:07:22 pm »
Each reader would then look for this value in itself. ie: ParamStr(0)

You cannot rely on ParamStr(0) returning the path of the executable - use Application.ExeName instead :-)

So, the code example you gave, it seems to be missing some parts.
Do you have a complete example on this I could see?

The sample code I supplied should be enough for you to create your own test project. I know the principle works on Windows because it is used for self-extracting archives, installers and so on. I haven't tried it on Linux. But since Linux (and AFAIK MacOS) does not support embedded resources in the same way Windows does, you should (in the name of portability) not rely on windows style resources for your project.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #18 on: August 20, 2016, 01:07:48 pm »
Hi technipixel

Fungus has a good idea/point (back a couple of posts).

I haven't tried it, but fungus is recommending placing your data at the end of your reader exe. The last 4 bytes of the exe will be the start location of your data. If that works on linux/windows, then, yes, I think thats better than Win32 resources.

So, you would create a reader which will compile for Windows/Linux/Mac.

You would then have the 3 exe's with your IDE. Depending on the target the user selects, you would load the exe, copy the data to the end with the start pos of the data.

Each reader would then look for this value in itself. ie: ParamStr(0)

Personally, I don't know why you want the book + exe together. Would'nt it be better to have a library of books accessed by the one exe?

Or, do you want some kinda protection? In which case, why not just Blowfish the book and make it available via HTTP? So, they download a reader. The reader shows the books available. and if they have a password, they can read them.

Im just guessing, since you haven't explained why you want to release a book that compresses to a few hundred kb released with a 1.7M+ exe

I'm not specifying any one type of project... just general content. EBook is just an example.

If you saw the two links on VBForum of What I did using VB.NET you'll understand...

Below are two images........
1) EXE (with funtionality) that loads an external RESOURCE FILE




« Last Edit: August 20, 2016, 01:10:18 pm by technipixel »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #19 on: August 20, 2016, 01:09:18 pm »
Hi technipixel

Fungus has a good idea/point (back a couple of posts).

I haven't tried it, but fungus is recommending placing your data at the end of your reader exe. The last 4 bytes of the exe will be the start location of your data. If that works on linux/windows, then, yes, I think thats better than Win32 resources.

So, you would create a reader which will compile for Windows/Linux/Mac.

You would then have the 3 exe's with your IDE. Depending on the target the user selects, you would load the exe, copy the data to the end with the start pos of the data.

Each reader would then look for this value in itself. ie: ParamStr(0)

Personally, I don't know why you want the book + exe together. Would'nt it be better to have a library of books accessed by the one exe?

Or, do you want some kinda protection? In which case, why not just Blowfish the book and make it available via HTTP? So, they download a reader. The reader shows the books available. and if they have a password, they can read them.

Im just guessing, since you haven't explained why you want to release a book that compresses to a few hundred kb released with a 1.7M+ exe

I'm not specifying any one type of project... just general content. EBook is just an example.

If you saw the two links on VBForum of What I did using VB.NET you'll understand...

Below are two images........
1) EXE (with funtionality) that loads an external RESOURCE FILE
2) Compiled EXE using CodeDom that compiles VB Code (had to code the resources to fetch external files. and embed into EXE - one file)

Here is the second image

2) Compiled EXE using CodeDom that compiles VB Code (had to code the resources to fetch external files. and embed into EXE - one file)
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #20 on: August 20, 2016, 01:13:24 pm »
Each reader would then look for this value in itself. ie: ParamStr(0)

You cannot rely on ParamStr(0) returning the path of the executable - use Application.ExeName instead :-)

So, the code example you gave, it seems to be missing some parts.
Do you have a complete example on this I could see?

The sample code I supplied should be enough for you to create your own test project. I know the principle works on Windows because it is used for self-extracting archives, installers and so on. I haven't tried it on Linux. But since Linux (and AFAIK MacOS) does not support embedded resources in the same way Windows does, you should (in the name of portability) not rely on windows style resources for your project.

Okay... so what is the "Universal" way to handle a external Resource File made using code?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Fungus

  • Sr. Member
  • ****
  • Posts: 354
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #21 on: August 20, 2016, 01:20:15 pm »
If a single executable with everything embedded in it is a requirement, you must "slip stream" the resources to the end of the executable as demonstrated. But the easiest way is to distribute multiple files as an installer / archive.

EDIT: If I can find the time I'll try to make a slip stream sample on Linux some time later :-)
« Last Edit: August 20, 2016, 01:22:24 pm by Fungus »

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #22 on: August 20, 2016, 01:58:12 pm »
If a single executable with everything embedded in it is a requirement, you must "slip stream" the resources to the end of the executable as demonstrated. But the easiest way is to distribute multiple files as an installer / archive.

EDIT: If I can find the time I'll try to make a slip stream sample on Linux some time later :-)

I am building your sample...

But for the life of me, I can't seem to call the LoadBook proc.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.  
  4.   //LoadBook;
  5.         Memo1.Text := LoadBook(TMemoryStream);
  6.  
  7. end;

I get error saying... Wrong Number of Paramaters
The function only has 1.

I tried 'Result' instead of TMemoryStream too, but error.

What is wrong?
« Last Edit: August 20, 2016, 02:02:34 pm by technipixel »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #23 on: August 20, 2016, 02:29:15 pm »
If a single executable with everything embedded in it is a requirement, you must "slip stream" the resources to the end of the executable as demonstrated. But the easiest way is to distribute multiple files as an installer / archive.

EDIT: If I can find the time I'll try to make a slip stream sample on Linux some time later :-)

I am building your sample...

But for the life of me, I can't seem to call the LoadBook proc.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.  
  4.   //LoadBook;
  5.         Memo1.Text := LoadBook(TMemoryStream);
  6.  
  7. end;

I get error saying... Wrong Number of Paramaters
The function only has 1.

I tried 'Result' instead of TMemoryStream too, but error.

What is wrong?

You need to create a variable of type TMemoryStream and then create instance of TMemoryStream into that variable. After you have your use of TMemoryStream instance, free it.

Code: Pascal  [Select][+][-]
  1. Var
  2.   AMemoryStream : TMemoryStream;
  3. begin
  4.   AMemoryStream := TMemoryStream.Create;  // create instance of TMemoryStream class
  5.   FreeAndNil(AMemoryStream); // free the instance
  6. end;

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #24 on: August 20, 2016, 02:36:13 pm »
My call to LoadBook function comes from this code by Fungus

Code: Pascal  [Select][+][-]
  1. Function LoadBook: TMemoryStream;
  2. Var
  3.   Src: TFileStream;
  4.   Pos: Int64;
  5. Begin
  6.   Src:= TFileStream.Create(Application.ExeName, fmOpenRead);
  7.   Try
  8.     //Get book offset
  9.     Src.Seek(SizeOf(Pos), soFromEnd);
  10.     Src.Read(Pos, SizeOf(Pos));
  11.     Src.Seek(Pos, soFromBeginning);
  12.     //Get book data
  13.     Result:= TMemoryStream.Create;
  14.     Result.CopyFrom(Src, Src.Size - Pos - SizeOf(Pos));
  15.   Finally
  16.     Src.Free;
  17.   End;
  18. End;

I get the error trying call that function.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Fungus

  • Sr. Member
  • ****
  • Posts: 354
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #25 on: August 20, 2016, 02:41:29 pm »
My call to LoadBook function comes from this code by Fungus

Code: Pascal  [Select][+][-]
  1. Function LoadBook: TMemoryStream;
  2. Var
  3.   Src: TFileStream;
  4.   Pos: Int64;
  5. Begin
  6.   Src:= TFileStream.Create(Application.ExeName, fmOpenRead);
  7.   Try
  8.     //Get book offset
  9.     Src.Seek(SizeOf(Pos), soFromEnd);
  10.     Src.Read(Pos, SizeOf(Pos));
  11.     Src.Seek(Pos, soFromBeginning);
  12.     //Get book data
  13.     Result:= TMemoryStream.Create;
  14.     Result.CopyFrom(Src, Src.Size - Pos - SizeOf(Pos));
  15.   Finally
  16.     Src.Free;
  17.   End;
  18. End;

I get the error trying call that function.

The function will only work if the executable has some data slipstreamed using CombineExeAndBook. Since you know that you are getting an error from LoadBook you are running the app in the debugger which means that there cannot be any data slipstreamed.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #26 on: August 20, 2016, 02:51:18 pm »
Quote
The function will only work if the executable has some data slipstreamed using CombineExeAndBook. Since you know that you are getting an error from LoadBook you are running the app in the debugger which means that there cannot be any data slipstreamed.

I do realize that...

If I understand your code right... it uses 3 EXE's

Application.Name (my IDE making app) - This creates the MyExe.exe using TemplateExe.exe

My var for creating exe

OutputFile: String = 'MyEXE.exe';
ExeFile: String = 'TemplateExe.exe';

So, how do I create the Templates.exe without the errors?

Do, I have this right?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Fungus

  • Sr. Member
  • ****
  • Posts: 354
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #27 on: August 20, 2016, 03:46:10 pm »
I've just been on the playground :-) The attached demo project works on Linux and should work just as fine on windows.

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #28 on: August 20, 2016, 04:34:10 pm »
I've just been on the playground :-) The attached demo project works on Linux and should work just as fine on windows.

THANKS... that seems cool!

Okay... I had to add the line readln; so I could see the console

So, what parts do I change to use a TForm and read in an RTF file into the memo text box?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

Handoko

  • Hero Member
  • *****
  • Posts: 5458
  • My goal: build my own game engine using Lazarus
Re: My Own 'IDE' --> Create My Own EXE's
« Reply #29 on: August 20, 2016, 05:32:22 pm »
You cannot rely on ParamStr(0) returning the path of the executable - use Application.ExeName instead :-)

I used ParamStr(0) several times. Although never have any issue so far, I'm interested to know any potential problem could happen. Can you please provide more information?

 

TinyPortal © 2005-2018