Page 1 of 1

PokeS without NULL-Termination

Posted: Wed Feb 02, 2005 11:07 am
by Andras
Hi,

I'd like to have an optional PokeS-Parameter for writing a string without adding a terminating NULL-Char...

Posted: Wed Feb 02, 2005 1:16 pm
by blueznl
basically, you only need to use a copymemory

CopyMemory(@string,addr,Length)

Code: Select all

Procedure x_pokes(addr.l,string.s,Length.l)
  Protected n
  ;
  ; *** as pokes() but will not write a terminating zero if the string is too long to fit
  ;
  n = Len(string)
  If n < Length
    PokeS(addr,string)
  Else
    CopyMemory(@string,addr,Length)
  EndIf
EndProcedure

Posted: Wed Feb 02, 2005 1:22 pm
by blueznl
well, oh, strings in structs, probably? :-)

that's why i'd love to have fixed length strings as well...

Posted: Wed Feb 02, 2005 3:34 pm
by Psychophanta
Blueznl, i've got this from current pb help:
Syntax

PokeS(*MemoryBuffer, Text$ [, Length])
Description

For advanced programmers only. Write a string (including the ending '0') to the specified memory address.

An optional length parameter (in bytes) can be specified that defines the length of the string itself, a zero will still be placed in memory after the poked string (ie. specifying 6 will write 7 bytes, 6 for the string, and the last byte will be zero)
Supported OS

Windows, AmigaOS, Linux
Perhaps, what Andras resquests is another optional parameter for PokeS instruction to tell it what is the byte value which delimitates the string.

Posted: Wed Feb 02, 2005 4:13 pm
by Andras
Thanks@Blueznl: You are right - CopyMemory should do what I wanted. The only advantage of PokeS would be, that you don't need to know, where a string is located... For example if the string is in a structure you need to know the offset...

Posted: Wed Feb 02, 2005 7:06 pm
by Psychophanta
Hey, PokeS() takes a pointer, just same as CopyMemory(). 8)

Posted: Wed Feb 02, 2005 7:17 pm
by blueznl
psycho, the problem is the zero

i'm pretty sure he's trying to fill up the string part of a struct... it's something i have ran into a few times before as well

all i want to do is:

structwhatever/fieldwhatever.c = "12345"

instead of overwiting a bunch of bytes with poke or copymemory

Re: PokeS without NULL-Termination

Posted: Sat Feb 22, 2014 1:25 am
by Foz
Can I do a little resurrecting of this (antique) thread?

+1

When I *have* to use PokeS because I'm changing the type of the string to the desired format (i.e. going from unicode to an ascii structure), I have to do a bunny hop of pokeing into temporary memory, then copying the temporary memory (minus the 0) into the correct field.

Re: PokeS without NULL-Termination

Posted: Sat Feb 22, 2014 9:52 am
by User_Russian
I agree.
It should be possible, disable the terminating null byte.

Re: PokeS without NULL-Termination

Posted: Tue Feb 25, 2014 10:16 pm
by blueznl
+1

I had to cook up my own PokeS just to get rid of that trailing zero...