CONTAINING_RECORD宏
//根据结构中某成员的地址得到整个结构的地址 struct msginfo { INT a; char b[20] = {"abc"}; }; void CtestThreadDlg::OnBnClickedButton18() { msginfo info = {}; info.a = 12; msginfo * p = CONTAINING_RECORD(info.b, msginfo, b); int d = p->a; }
VS2015编译运行
//根据结构中某成员的地址得到整个结构的地址 struct msginfo { INT a; char b[20] = {"abc"}; }; void CtestThreadDlg::OnBnClickedButton18() { msginfo info = {}; info.a = 12; msginfo * p = CONTAINING_RECORD(info.b, msginfo, b); int d = p->a; }
VS2015编译运行