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

来源:互联网 发布:拍拍网 淘宝网 编辑:程序博客网 时间:2024/04/28 12:19

前言: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相对于基地址的偏移