【发布时间】:2020-05-08 20:04:48
【问题描述】:
我有以下 COM 接口和实现该接口的 COM 对象:
[
object,
uuid(8FF1207F-24DD-4F34-B6CB-D90904CF4094),
dual
]
interface IThrowingProperty : IDispatch
{
[id(1), propget]
HRESULT IntPropertyValue([out, retval] int* pVal);
}
[
uuid(3869048C-A14F-4536-9FFC-0A4ECAEF2B08)
]
coclass ThrowingProperty
{
[default] interface IThrowingProperty;
};
此属性总是返回错误:
STDMETHODIMP CThrowingProperty::get_IntPropertyValue(/*[out,retval]*/ int* pVal)
{
return E_NOTIMPL;
}
但是当我尝试在 Powershell 中访问它时,我没有收到任何错误,并且属性值等于 $null:
$PropertyWillThrow = New-Object -ComObject "PowershellCom.ThrowingProperty"
$PropertyWillThrow.IntPropertyValue
$PropertyWillThrow.IntPropertyValue -eq $null
是否可以在不将属性更改为方法的情况下从 Powershell 中的 COM 属性中获取错误? 谢谢
【问题讨论】:
标签: powershell exception error-handling null com