未分类--Windows API--SafeArrayGetElement

150 篇文章 0 订阅
31 篇文章 0 订阅

原文来自MSDN Library for Visual Studio 2008 SP1,翻译部分仅为个人观点,想要看更多信息请看MSDN,如有版权问题请联系QQ 643166601,邮件643166601@qq.com

 

Platform Builder for Microsoft Windows CE 5.0   

SafeArrayGetElement

This function retrieves a single element of the array.
这个函数取回数组中的一个单个元素。
HRESULT SafeArrayGetElement(
  SAFEARRAY FAR* psa,
  long FAR* rgIndices,
  void FAR* pv
);
Parameters
psa
[in] Pointer to an array descriptor created by SafeArrayCreate.
指针指向由SafeArrayCreate创建的一个数组描述符。
rgIndices
[in] Pointer to a vector of indexes for each dimension of the array.
指针指向数组的每个维的模版的索引。
The right-most (least significant) dimension is rgIndices[0].
这个最右边(最重要的)维数是rgIndices[0]。
The left-most dimension is stored at rgIndices[psa->cDims –1].
这个最左边维数存储在rgIndices[psa->cDims –1]。
pv
[out] Void pointer to the location to place the element of the array.
空指针去放置数组的元素。
Return Values
Returns the HRESULT values shown in the following table.
返回HRESULT值展示在下表。
Value Description
S_OK
Success.
成功。
DISP_E_BADINDEX
The specified index is invalid.
这个指定的索引是无效的。
E_INVALIDARG 
An argument is invalid.
一个无效的说法。
E_OUTOFMEMORY 
Memory could not be allocated for the element.
不能给这个元素分配内存。
Remarks
This function calls SafeArrayLock and SafeArrayUnlock automatically, before and after retrieving the element.
这个函数自动地调用SafeArrayLock 和 SafeArrayUnlock,在取回元素的前后。
The caller must provide a storage area of the correct size to receive the data.
调用者必须提供一个正确尺寸的存储区域去接收数据。
If the data element is a string, object, or variant, the function copies the element in the correct way.
如果这个数据元素是字符串,对象或变体,这个函数拷用正确的方式拷贝元素。
Passing invalid (and under some circumstances NULL) pointers to this function causes an unexpected termination of the application.
传入无效的(在某些情况下NULL)指针到这个函数引起意外的程序终止。
Example
STDMETHODIMP CEnumPoint::Next(
  ULONG celt,
  VARIANT FAR rgvar[],
  ULONG FAR* pceltFetched)
{
  unsigned int i;
  long ix;
  HRESULT hresult;

  for(i = 0; i < celt; ++i)
    VariantInit(&rgvar[i]);

  for(i = 0; i < celt; ++i){
    if(m_iCurrent == m_celts){
    HRESULT = ReportResult(0, S_FALSE, 0, 0);
      goto LDone;
  }

    ix = m_iCurrent++;
    HRESULT = SafeArrayGetElement(m_psa, &ix, &rgvar[i]);
    if(FAILED(hresult))
      goto LError0;
  }
  HRESULT = NOERROR;

LDone:;
  *pceltFetched = i;
  return hresult;

LError0:;
  for(i = 0; i < celt; ++i)
    VariantClear(&rgvar[i]);
  return hresult;
}
Requirements
OS Versions: Windows CE 2.0 and later.
Header: Oleauto.h.
Link Library: Oleaut32.lib.

See Also
Automation Functions | SafeArrayCreate | SafeArrayLock | SafeArrayUnlock

 


--------------------------------------------------------------------------------

Last updated on Wednesday, September 14, 2005

© 2005 Microsoft Corporation. All rights reserved.

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值