That does help some Daniel. I do in fact need to work with C style null terminated strings because when passing a structure to an underlying OS via nativecall, you have no control over what the underlying libraries want. An Example:
class myStruct is repr('CStruct') { HAS int8 @.Path[MAX_PATH] is CArray; method path { blob-from-pointer(Pointer.new(nativecast(Pointer, self)+4), :elems(MAX_PATH)); } } sub Fill(myStruct) is native('Kernel32') { * }; my myStruct $struct .= new; Fill($struct); say $struct.path; As you can imagine, @.PATH has a static buffer that is MAX_PATH length, and the strings stored there are <= MAX_PATH in length. The only way to get them is to look for that NULL. On Wed, Jun 9, 2021 at 10:46 AM Daniel Sockwell <dan...@codesections.com> wrote: > Hi Paul, > > If you _do_ want/need to work with C-style null-terminated strings, you > can use the (core) > NativeCall library. So, given your example: > > > my Buf $b .= new([72, 105, 0, 32, 97, 103, 97, 105, 110, 0]); > > say $b.decode; > > I would expect this to print 'Hi'. > > > > Instead it prints 'Hi again'. > > You can write: > > use NativeCall; > say nativecast(str, $b) # prints 'Hi' > > Hope that helps! > > – codesections > -- __________________ :(){ :|:& };: