Embed a file in the DataSection and write it to the temp directory

Everything else that doesn't fall into one of the other PB categories.
hoangdiemtinh
User
User
Posts: 97
Joined: Wed Nov 16, 2022 1:51 pm

Embed a file in the DataSection and write it to the temp directory

Post by hoangdiemtinh »

I am new to PB.
My primary language is not US/UK. I am using Google Translate.

I have a commandline executable file. I want to package it with the exe file made from PB.

Does PB support this?

Embed a file in the DataSection and write it to the temp directory.
PC: Windows 10 x64, 8GB RAM. PB ver: 6.x
--
I love PB5 vs PB6 :)
PeDe
Enthusiast
Enthusiast
Posts: 284
Joined: Sun Nov 26, 2017 3:13 pm

Re: Embed a file in the DataSection and write it to the temp directory

Post by PeDe »

You may have to activate the option for compiling in the source directory in the compiler options 'Compile/Run' so that the EXE is found without a path.

Peter

Code: Select all

EnableExplicit

#ExeName = "prog.exe"
Define iFileNr.i, sFileName.s, iResult.i

sFileName = GetTemporaryDirectory() + #ExeName
iFileNr = CreateFile(#PB_Any, sFileName)

If iFileNr
  iResult = WriteData(iFileNr, ?ExeStart, ?ExeEnd - ?ExeStart)
  Debug "Bytes: " + iResult + " - File: " + sFileName

  CloseFile(iFileNr)
  DeleteFile(sFileName)
EndIf

DataSection
  ExeStart:
  IncludeBinary #ExeName
  ExeEnd:
Post Reply