CONTAINING_RECORD宏
更新:HHH   时间:2023-1-7


//根据结构中某成员的地址得到整个结构的地址
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编译运行

返回编程语言教程...