IDebugHost::GetDefaultMetadata 方法 (dbgmodel.h)
GetDefaultMetadata 方法返回一个默认元数据存储,该存储可用于某些操作 (例如,在没有传递显式元数据时字符串转换) 。 这样,调试主机就可以对某些数据的呈现方式进行一些控制。 例如,默认元数据可能包含 PreferredRadix 键,允许主机指示是否应以十进制或十六进制形式显示序号(如果未指定)。
请注意,默认元数据存储中的属性值必须手动解析,并且必须传递要查询其默认元数据的对象。 应使用 GetKey 方法代替 GetKeyValue。
语法
HRESULT GetDefaultMetadata(
IKeyStore **defaultMetadataStore
);
参数
defaultMetadataStore
此处返回调试主机的默认元数据存储。
返回值
此方法返回指示成功或失败的 HRESULT。
注解
代码示例
使用示例 (通常由数据模型本身) 调用:
ComPtr<IDebugHost> spHost; /* get the debug host */
ComPtr<IModelObject> spObject; /* find some object that we want default metadata for */
ComPtr<IKeyStore> spDefaultMetadata;
if (SUCCEEDED(spHost->GetDefaultMetadata(&spDefaultMetadata)))
{
// Query the preferred display radix for spObject. We must resolve the
// property manually and pass spObject as the context object.
// This allows the default store to do things like say "radix is 10 for
// signed types and 16 for unsigned types"
ComPtr<IModelObject> spRadixKey;
if (SUCCEEDED(spDefaultMetadata->GetKey(L"PreferredRadix", &spRadixKey, nullptr)))
{
// There is a default radix in which to display spObject. Resolve
// the property manually.
ModelObjectKind kind;
if (SUCCEEDED(spRadixKey->GetKind(&kind)))
{
if (kind == ObjectPropertyAccessor)
{
VARIANT vtProp;
if (SUCCEEDED(spRadixKey->GetIntrinsicValue(&vtProp)))
{
// There is an *in process* guarantee that the IUnknown
// is IModelPropertyAccessor because of ObjectPropertyAccessor
IModelPropertyAccessor *pProperty =
static_cast<IModelPropertyAccessor *>(vtProp.punkVal);
ComPtr<IModelObject> spRadix;
if (SUCCEEDED(pProperty->GetValue(L"PreferredRadix",
spObject.Get(),
&spRadix)))
{
// spRadix contains the display radix. Unbox
// with GetIntrinsicValueAs.
}
VariantClear(&vtProp);
}
}
else
{
// spRadixKey contains the display radix. Unbox
// with GetIntrinsicValueAs.
}
}
}
}
实现示例 (主机通常会) 执行此操作:
// Define a property which returns a radix of 16 for unsigned values and 10
// for signed values
class RadixProperty :
public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags<
Microsoft::WRL::RuntimeClassType::ClassicCom
>,
IModelPropertyAccessor
>
{
public:
IFACEMETHOD(GetValue)(_In_ PCWSTR /*pwszKeyName*/,
_In_opt_ IModelObject *pContextObject,
_Out_ IModelObject **ppValue)
{
HRESULT hr = S_OK;
*ppValue = nullptr;
unsigned int radix = 0;
if (pContextObject != nullptr)
{
ModelObjectKind kind;
hr = pContextObject->GetKind(&kind);
if (SUCCEEDED(hr) && kind == ObjectIntrinsic)
{
VARIANT vtValue;
if (SUCCEEDED(pContextObject->GetIntrinsicValue(&vtValue)))
{
switch(vtValue.vt)
{
case VT_I1: case VT_I2: case VT_I4: case VT_I8:
radix = 10;
break;
case VT_UI1: case VT_UI2: case VT_UI4: case VT_UI8:
radix = 16;
break;
}
VariantClear(&vtValue);
}
}
}
ComPtr<IModelObject> spResultRadix;
if (SUCCEEDED(hr) && radix != 0)
{
VARIANT vtRadix;
vtRadix.vt = VT_UI4;
vtRadix.ulVal = radix;
hr = GetManager()->CreateIntrinsicObject(ObjectIntrinsic,
&vtRadix,
&spResultRadix);
}
else if (SUCCEEDED(hr) && radix == 0)
{
// We succeeded but don't have a defined radix. Return no value.
hr = GetManager()->CreateNoValue(&spResultRadix);
}
if (SUCCEEDED(hr))
{
*ppValue = spResultRadix.Detach();
}
return hr;
}
IFACEMETHOD(SetValue)(_In_ PCWSTR /*pwszKeyName*/,
_In_opt_ IModelObject * /*pContextObject*/,
_In_ IModelObject * /*pValue*/)
{
return E_NOTIMPL;
}
};
// Implementation on the implementation class for IDebugHost:
IFACEMETHOD(GetDefaultMetadata)(_Out_ IKeyStore **ppMetadata)
{
HRESULT hr = S_OK;
*ppMetadata = nullptr;
ComPtr<IKeyStore> spMetadata;
hr = GetManager()->CreateMetadataStore(&spMetadata));
if (SUCCEEDED(hr))
{
ComPtr<RadixProperty> spProperty = Microsoft::WRL::Make<RadixProperty>();
if (spProperty == nullptr)
{
hr = E_OUTOFMEMORY;
}
else
{
VARIANT vtProp;
vtProp.vt = VT_UNKNOWN;
vtProp.punkVal = static_cast<IModelPropertyAccessor *>(spProperty.Get());
ComPtr<IModelObject> spPropertyObject;
hr = GetManager()->CreateIntrinsicObject(ObjectPropertyAccessor,
&vtProp,
&spPropertyObject));
if (SUCCEEDED(hr))
{
hr = spDefaultMetadata->SetKey(L"PreferredRadix",
spPropertyObject.Get(),
nullptr));
}
}
}
if (SUCCEEDED(hr))
{
*ppMetaData = spMetadata.Detach();
}
return hr;
}
要求
要求 | 值 |
---|---|
Header | dbgmodel.h |