Page 1 of 1

C# Structure to PB

Posted: Sat Dec 09, 2017 9:02 pm
by Wolfram
How can I define this structure in PB.
The problem is data has a dynamic size (chunkSize) and I can't read p.

Code: Select all

typedef struct {
  ID      chunkID;
  long    chunkSize;
  char    data[]; //how does this work?
  char    p;
} LabelChunk;

Code: Select all

Structure lablStruc
  chunkID.s{4}
  chunkSize.l
  data ;[]  the size is the chunkSize
  p.a
EndStructure

Re: C# Structure to PB

Posted: Sat Dec 09, 2017 9:33 pm
by infratec
Hi,

Code: Select all

Structure labelChunkStructure
  chunkID.a[4]
  chunkSize.l
  chunkData.a[0]
  p.a
EndStructure


*Buffer = AllocateMemory(100)
PokeS(*Buffer + 0, "TEST", 4, #PB_Ascii|#PB_String_NoZero)
PokeL(*Buffer + 4, 10)
For i = 0 To 9
  PokeA(*Buffer + 8 + i, i)
Next i
PokeA(*Buffer + 4 + 4 + 10, 'E')

*Ptr.labelChunkStructure = *Buffer
If PeekS(@*Ptr\chunkID[0], 4 , #PB_Ascii) = "TEST"
  
  For i = 0 To *Ptr\chunkSize - 1
    Debug *Ptr\chunkData[i]
  Next i
  
  ; no direct access to \p
  Debug Chr(PeekA(*Ptr + 8 + *Ptr\chunkSize))
  
EndIf
You have no direct access to \p
And you have to use .a for the ID, because .s reserves 8 Bytes (Unicode) and you can not tell PB tat it is Ascii.

Bernd

Re: C# Structure to PB

Posted: Sat Dec 09, 2017 10:16 pm
by Wolfram
Thanks !