I have the following Struct :
typedef struct _info{
DWORD myInfo;
BYTE *pInfo;
LPWSTR ExtData;
} Info;
I represented this struct using NativeCall
thus:
class Info is repr('CStruct') {
has int32 $.myInfo;
has Pointer[int8] $.pInfo ;
has Pointer[int16] $.ExtData;
}
Is this representation okay? How can I access and set the data which is pointed to by $.pInfo
?
The representation seems ok to me... Given this invented C library: (please don't pick on my C foo - its beside the point)
then your Raku struct definition using NativeCall more or less works:
A run of this produces;
Alternatively, one can hide more of the 'glue' inside the Raku class;
... a much cleaner look. It similarly produces;
Notes:
(1) You call the .deref() method on attributes of type Pointer to get the actual data being pointed to.
(2) The NativeCall documentation has to be read more than once ;-)
(3) No matter what I tried, I couldn't modify the data being referenced via pointers - I kept getting "Can't modify immutable data".
(4) YMMV