On Sunday, 28 February 2021 at 09:18:56 UTC, Rumbu wrote:
On Sunday, 28 February 2021 at 09:04:49 UTC, Rumbu wrote:
On Sunday, 28 February 2021 at 07:05:27 UTC, Jack wrote:
I'm using a windows callback function where the user-defined
value is passed thought a LPARAM argument type. I'd like to
pass my D array then access it from that callback function.
How is the casting from LPARAM to my type array done in that
case?
for example, I need something like this to work:
int[] arr = [1, 2, 3];
long l = cast(long) cast(void*) arr.ptr;
int[] a = cast(int[]) cast(void*) l;
LPARAM is not long on 32 bits, it's int. Use LPARAM instead of
long.
And you are passing only the address of the first element this
way, loosing the array/slice length. This should work, but keep
in mind that you have no warranty that the array stays in
memory and it is not garbage collected.
int[] arr = [1, 2, 3];
LPARAM l = cast(LPARAM)cast(void*)&arr;
int[] a = *cast(int[]*)(cast(void*)l);
Do the windows APIs expect the length in memory rather than as a
parameter?
Also Rumbu can you check your email - I may have emailed you on
an old email address by accident, but it's about the blog and it
will be from mh240@...