Page 1 of 1

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

Posted: Sat Jun 01, 2024 5:10 am
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.

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

Posted: Sat Jun 01, 2024 7:19 am
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: