How can I make this work?

evilrat evilrat666 at gmail.com
Sun Feb 28 07:40:04 UTC 2021


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;

Should already work like that. Just be aware that array can be 
garbage collected if no references for it are kept somewhere else 
between set callback and the actual call, otherwise you can get 
some random garbage.

Also be aware that such casts 99% basically a speculation, there 
is no guarantee that returned data is actually an int[].



More information about the Digitalmars-d-learn mailing list