如何评估IDebugProperty2的参考?

问题描述

如何在Microsoft.VisualStudio.Debugger.IDebugProperty2获取对象的地址? 前置&&expression)不是解决方案,因为我会失去财产的孩子,但这正是我想要的。

我正在通过IDebugExpression2::EvaluateSync获得property2,它以变量名作为表达式。

解决方法

如果内部的变量是指针(引用类型的变量),则它返回地址。

if (property2.GetMemoryContext(out var memoryContext2) != (int) HResults.S_OK || memoryContext2 == null)
  return 0;

var info = new CONTEXT_INFO[1];
memoryContext2.GetInfo(enum_CONTEXT_INFO_FIELDS.CIF_ADDRESS,info);

return long.Parse(info[0].bstrAddress.Substring(2),System.Globalization.NumberStyles.HexNumber);