How does cast(SomeObj) (cast(void*) ptrFromC) work?

David Zhang via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 25 18:28:48 PST 2017


I was trying to figure out why calling an object's function from 
a wndProc that modified the object's state didn't actually change 
anything. Wrapping the GetWindowLongPtr in a cast(void*) seems to 
make it work. What am I missing about this? I though that object 
references were really just pointers with special 
restrictions/behaviors?

Old:
     window = cast(Win32Window) GetWindowLongPtr(hwnd, 
GWLP_USERDATA);

New:
     window = cast(Win32Window) (cast(void*) 
GetWindowLongPtr(hwnd, GWLP_USERDATA));


More information about the Digitalmars-d-learn mailing list