Array BASE_OFFSET from Essential COM

I am reading Essential COM and have come across the macro "BASE_OFFSET" from chapter 2 of the book, and I really do not understand its syntax or why this is so.

#define BASE_OFFSET(ClassName, BaseName) \
(DWORD_PTR(static_cast<BaseName*>(reinterpret_cast<ClassName*>(0x10000000))) - 0x10000000)

Can someone explain this macro and how do we use it? In fact, the book uses this macro, but since I do not understand it, I do not see its practical use. Thank you so much in advance.

+5
source share
1 answer

The macro creates a dummy pointer to ClassNameusing reinterpret_cast, and then passes it to BaseNameusing static_cast.

. - , BaseName ClassName. offsetof, .

Diagram showing an example

, .

+7

All Articles