1. 程式人生 > >計算結構體基地址的巨集定義

計算結構體基地址的巨集定義

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