未分类--Windows API--SafeArrayGetElement

来源:互联网 发布:行之愈笃 则知之益明 编辑:程序博客网 时间:2024/06/07 02:37

原文来自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 0
原创粉丝点击