How add multiple strings in exe?

Just starting out? Need help? Post your questions and find answers here.
Mark.s
User
User
Posts: 16
Joined: Wed Dec 17, 2008 1:43 pm
Location: Finland

How add multiple strings in exe?

Post by Mark.s »

My question is in subject. But, how i can add an multiplelines text to exe,
without destroying that exe. i need an example of that.

Text is in array, like this:

Code: Select all

Dim Array.s(2)
Array(1) = "newline"
Array(2) = "line 2"
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

You mean like this?

Code: Select all

MyString.s = #CRLF$+"This"+#CRLF$+"is"+#CRLF$+"a"+#CRLF$+"multiline"+#CRLF$+"string"
MessageRequester("",Mystring)
Compile as exe then look inside with notepad :).
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
Mark.s
User
User
Posts: 16
Joined: Wed Dec 17, 2008 1:43 pm
Location: Finland

Post by Mark.s »

Inf0Byt3 wrote:You mean like this?
Sorry my bad English, but i mean somelike this:

Code: Select all

Dim array.s(1)

array.s(0) = "Test"
array.s(1) = "another test"

Dim message.s(1)
    
pfile.s="test.exe"
psize=FileSize(pfile) 
file=OpenFile(0, pfile) 

If file 
  FileSeek(0,psize)  
  For i = 0 To 1
  	WriteStringN(0,array.s(i)) 
    Debug array.s(i)
  Next i
  MessageRequester("Status", "Added text to exe!") 
  CloseFile(0) 
EndIf

fsize=FileSize(pfile) 
file=ReadFile(0, pfile) 

If file 
  FileSeek(0,psize) 
  For i = 0 To 1
    message.s(i)=ReadString(0) 
    MessageRequester("Success!", message(i))  
    Debug message.s(i)
  Next i
  CloseFile(0) 
EndIf
But problem is now: This not work on compiled exe's, its work only in editor.

So when i start compiled exe, there comes messagebox, but in msbox
there no are text. So what need do to, get that working on exes?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Well, you cannot append strings to an exe whilst it is running as Windows locks the file completely.

What you can do is append strings to the exe whilst it is not running and if you append some kind of pointer to point to the first string, then there is nothing stopping you opening the exe for reading whilst it is running and thus retrieving the strings etc.

Take a self-extracting archive for example, here (typically) a copy of the running exe would be used and data appended to that etc.
I may look like a mule, but I'm not a complete ass.
Post Reply