I’m reading someone’s (public) source code and I’ve come across this line and have no idea what it does. I’ve tried decomposing it but it always ends up confusing me in spite of what I try.
uintptr_t* pInterfaceVTable = (uintptr_t*)*(uintptr_t*)pd3dDevice;
pd3dDevice is a LPDIRECT3DDEVICE9, which is a IDirect3DDevice9*. An IDirect3DDevice9 is a class that inherits off IUnknown, and both implement a bunch of virtual functions.
Could someone more worldly please help me with what this code does, line-by-line?
Thank you very much for your time!
uintptr_t is an integer type that can store a pointer.
The author assumes (knows?) that the first entry in IDirect3DDevice9 is a pointer, so he casts IDirect3DDevice9 to (uintptr_t*) and dereferences it to access that pointer. Then he casts that uintptr_t again to a pointer (to uintptr_t) to assign it to pInterfaceVTable.
As mentioned in the comment and by AndyT, that is were the used compiler stores the pointer to the VTable, but that is not guaranteed by C++.