安全数组 - 将计数设置为零
如果要返回的安全数组计数为零,以下代码是否有效?我还应该做点别的吗?
HRESULT GetAlarms(FAULT_TYPE eAlarmType, long alarmLevel, VARIANT* pvarAlamLst)
{
pvarAlamLst->vt = VT_ARRAY |VT_VARIANT;
pvarAlamLst->parray = NULL;
return S_OK;
}
will the following code work, if the safe array count to be returned is zero? Should I do anything else?
HRESULT GetAlarms(FAULT_TYPE eAlarmType, long alarmLevel, VARIANT* pvarAlamLst)
{
pvarAlamLst->vt = VT_ARRAY |VT_VARIANT;
pvarAlamLst->parray = NULL;
return S_OK;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pArray
是一个LPSAFEARRAY
并且应该这样对待。因此,您需要SAFEARRAY
函数(宏)。SAFEARRAY
本身没有“计数”的概念,它是一个可变维度数组。一维SAFEARRAY
的大小可以为 0,但二维SAFEARRAY
的大小为 0x0(或 1x0)。特别是,MSDN 将
VT_ARRAY
记录为“parray
中的指针指向数组描述符”,但NULL
并不指向数组描述符。pArray
is aLPSAFEARRAY
and should be treated as such. Therefore you need theSAFEARRAY
functions (macros).SAFEARRAY
doesn't have a concept of "count" as such, it's a variable-dimension array. A one-dimensionalSAFEARRAY
can have size 0, but a 2DSAFEARRAY
would have size 0x0 (or 1x0).In particular, MSDN documents
VT_ARRAY
as "The pointer inparray
points to an array descriptor", butNULL
doesn't point to an array descriptor.