I'm including several text files into my EXE via the IncludeBinary command.
The problem occurs when I want to access the text I do peeks(?label_name) but that spits *everything* that was included in the DataSection using IncludeBinary after the text file - including other text, binary icon data, RTF data etc. Should I just not do that, or access that data in another way?
Thanks!
Including text files with IncludeBinary (Problems)
Including text files with IncludeBinary (Problems)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Well, the problem here is, that PeekS() only stops at a NULL character, not
CRLF, which marks the end of a line in a text file.
(ReadString() does stop at both.)
There is no NULL in the file, even not at the end, so it never stopps reading.
You could put a "Data.b 0" directly after the includebinary command. This
would make PeekS() stop there. But still gives you the whole file, not
just a line.
If you want a single line, you'll have to parse that string yourself i guess.
Timo
CRLF, which marks the end of a line in a text file.
(ReadString() does stop at both.)
There is no NULL in the file, even not at the end, so it never stopps reading.
You could put a "Data.b 0" directly after the includebinary command. This
would make PeekS() stop there. But still gives you the whole file, not
just a line.
If you want a single line, you'll have to parse that string yourself i guess.
Timo
quidquid Latine dictum sit altum videtur
- tinman
- PureBasic Expert

- Posts: 1102
- Joined: Sat Apr 26, 2003 4:56 pm
- Location: Level 5 of Robot Hell
- Contact:
Re: Including text files with IncludeBinary (Problems)
Well the files will be included but you won't have null terminators on them. You'll need to have something like:
DataSection
text1:
IncludeBinary "my_text_file"
Data.b 0
text2:
IncludeBinary "blahblah"
Data.b 0
EndDataSection
DataSection
text1:
IncludeBinary "my_text_file"
Data.b 0
text2:
IncludeBinary "blahblah"
Data.b 0
EndDataSection
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
(WinXPhSP3 PB5.20b14)
Yea, I wanted the whole file. Excellent guys, thank you!
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
Did you try adding a ?label_end flag in your includebinary data so you can specify where PeekS() should stop reading?
Notice the syntax for PeekS() ...
Text$ = PeekS(*MemoryBuffer [, Length])
so try this maybe...
Text$ = PeekS(?Label_Start,?Label_End-?Label_Start)
DataSection
?Label_Start:IncludeBinary "Textfile.txt"
?Label_End
EndDataSection
Notice the syntax for PeekS() ...
Text$ = PeekS(*MemoryBuffer [, Length])
so try this maybe...
Text$ = PeekS(?Label_Start,?Label_End-?Label_Start)
DataSection
?Label_Start:IncludeBinary "Textfile.txt"
?Label_End
EndDataSection
you probably already solved it, but it might be usefull to someone else...
Code: Select all
Procedure.s x_peeks(addr.l,terminator.s,l.l)
Protected p.l, string.s,terminator_l.l
Global x_peeks_read.l
;
; *** read a string from memory until terminating condition is met
;
;
; in: addr.l - location in memory
; terminator.s - seperator, if you're looking for zeroes use regular peeks()
; l.l - max length
; retval: - string found
; out: x_peeks_read.l - nr. of bytes read from memory
;
; notes:
;
; - x_peeks_read does not have To be equal To Length of string found
; - terminating condition can be string, a null character, or a maximal length
;
terminator_l = Len(terminator)
p = 0
string = ""
If l > 0 And terminator_l > 0
Repeat
string = string+Chr(PeekB(addr+p) & $FF)
p = p+1
Until Right(string,terminator_l) = terminator Or p=l Or PeekB(addr+p)=0
If Right(string, terminator_l) = terminator
string = x_chop(string,0,terminator_l)
EndIf
EndIf
x_peeks_read = p
ProcedureReturn string
EndProcedure
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )

