计算结构体基地址的宏定义

前言:2014-08-06记录在hi baidu上,现在移过来

winnt.h中定义的宏

//
// Calculate the address of the base of the structure given its type, and an
// address of a field within the structure.
//
#define CONTAINING_RECORD(address, type, field) ((type *)( \

                                                  (PCHAR)(address) - \

                                                  (ULONG_PTR)(&((type *)0)->field)))

(ULONG_PTR)(&((type*)0)->field) 计算field相对于基地址的偏移


版权声明:本文为wonderdaydream原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。