[Prev][Next][Index][Thread]
Re: c-ffi question involving c-struct
Hi Chris,
> I want to call an API function that takes a pointer to some structures
> and a count of the number of structures. So I use make(...) to create
> a number of my structures:
>
> define C-struct <INPUT>
> slot type-value :: <DWORD>;
> pointer-type-name: <LPINPUT>;
> end C-struct <INPUT>;
>
> let key-input = make(<LPINPUT*>, element-count: 3);
> key-input[0].type-value := 0; // error here
>
> I get an error on the indicated line saying 'no next method'. Any
> ideas how I achieve this sort of thing?
I think you need to use pointer-value-address(). The array operations
map like this:
(Dylan) tarray[i] == (Dylan) pointer-value(tarray, index: i) == (C) tarray[i]
Except this doesn't work in Dylan where t is a struct type. However,
there's also:
(Dylan) pointer-value-address(tarray, index: i) == (C) &(tarray[i])
which allows you to do what you want:
let key-input = make(<LPINPUT*>, element-count: 3);
pointer-value-address(key-input, index: 0).type-value := 0;
The restriction on pointer-value() and structs is there because it was
thought that some people would expect it to copy the embedded struct
while some would expect to get a pointer to the existing struct. To be
on the safe side it was simply disabled, leaving clients have to make
that choice explicitly.
-- Keith
Follow-Ups:
References: