C# Structure to PB

Just starting out? Need help? Post your questions and find answers here.
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

C# Structure to PB

Post 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
macOS Catalina 10.15.7
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: C# Structure to PB

Post 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
Wolfram
Enthusiast
Enthusiast
Posts: 568
Joined: Thu May 30, 2013 4:39 pm

Re: C# Structure to PB

Post by Wolfram »

Thanks !
macOS Catalina 10.15.7
Post Reply