Help Center

DSAFEARRAY.Getmethod

Retrieves a single element of the array.

COMmethodDSafeArray.incdocumented

Syntax

FUNCTION Get (BYVAL prgIndices AS LONG PTR, BYVAL pData AS ANY PTR) AS HRESULT
FUNCTION Get (BYVAL prgIndices AS LONG PTR, BYREF bsData AS BSTRING) AS HRESULT
FUNCTION Get (BYVAL prgIndices AS LONG PTR, BYREF dvData AS DVARIANT) AS HRESULT
FUNCTION Get (BYVAL idx AS LONG, BYVAL pData AS ANY PTR) AS HRESULT
FUNCTION Get (BYVAL idx AS LONG, BYREF bsData AS BSTRING) AS HRESULT
FUNCTION Get (BYVAL idx AS LONG, BYREF dvData AS DVARIANT) AS HRESULT
FUNCTION Get (BYVAL cElem AS LONG, BYVAL cDim AS LONG, BYVAL pData AS ANY PTR) AS HRESULT
FUNCTION Get (BYVAL cElem AS LONG, BYVAL cDim AS LONG, BYREF bsData AS BSTRING) AS HRESULT
FUNCTION Get (BYVAL cElem AS LONG, BYVAL cDim AS LONG, BYREF dvData AS DVARIANT) AS HRESULT

Parameters

NameDescription
prgIndicesPointer to a vector of indexes for each dimension of the array. The right-most (least significant) dimension is rgIndices(0). The left-most dimension is stored at pgIndices(@psa.cDims – 1).
pDataPointer to the location to place the element of the array.
bsDataA BSTRING passed by reference that will receive the result.
dvDataA DVARIANT passed by reference that will receive the result.
idxIndex of the element.
pDataPointer to the location to place the element of the array.
bsDataA BSTRING passed by reference that will receive the result.
dvDataA DVARIANT passed by reference that will receive the result.
cElemIndex of the element.
cDimDimension of the array.
pDataPointer to the location where to place the element of the array.
bsDataA BSTRING passed by reference that will receive the result.
dvDataA DVARIANT passed by reference that will receive the result.

Description

Retrieves a single element of the array.

Multidimensional array:

One-dimensional array:

Two-dimensional array:

First element, then dimension, e.g. 2, 1 (element 2, first dimension), 1, 2 (element 1, 2nd dimension).

Remarks

This method calls SafearrayLock and SafearrayUnlock automatically, before and after retrieving the element. 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.

Examples

' // One-dimensional array of VT_BSTR DIM dsa AS DSAFEARRAY = DSAFEARRAY(VT_BSTR, 2, 1) dsa.PutStr(1, "Test string 1") print dsa.GetStr(1) dsa.PutStr(2, "Test string 2") print dsa.GetStr(2)

' // One-dimensional array of VT_VARIANT DIM dsa AS DSAFEARRAY = DSAFEARRAY(VT_VARIANT, 5, 1) DIM dv1 AS DVARIANT = "Test variant 1" dsa.Put(1, dv1) DIM dvOut AS DVARIANT dsa.Get(1, dvOut) print dvOut DIM dv2 AS DVARIANT = "Test variant 2" dsa.Put(1, dv2) dsa.Get(1, dvOut) print dvOut

' // Two-dimensional array of BSTR ' // 2D: elements = 5, lower bound = 1 ' // 2D: elements = 3, lower bound = 1 DIM rgsabounds(0 TO 1) AS SAFEARRAYBOUND = {(5, 1), (3, 1)} DIM csa AS DSAFEARRAY = DSAFEARRAY(VT_BSTR, 2, @rgsabounds(0))

' // array index: first element, first dimension DIM rgidx(0 TO 1) AS LONG = {1, 1} DIM bs1 AS BSTRING = "Test string 1" ' // Put the value dsa.Put(@rgidx(0), bs1) ' // Get the value DIM bsOut AS BSTRING dsa.Get(@rgidx(0), bsOut) print bsOut ' // array index: second element, first dimension rgidx(0) = 2 : rgidx(1) = 1 ' // Put the value DIM bs2 AS BSTRING = "Test string 2" dsa.Put(@rgidx(0), bs2) ' // Get the value dsa.Get(@rgidx(0), bsOut) print bsOut

' // array index: first element, second dimension rgidx(0) = 1 : rgidx(1) = 2 ' // Put the value DIM bs3 AS BSTRING = "Test string 3" dsa.Put(@rgidx(0), bs3) ' // Get the value dsa.Get(@rgidx(0), bsOut) print bsOut

' // array index: second element, second dimension rgidx(0) = 2 : rgidx(1) = 2 ' // Put the value DIM bs4 AS BSTRING = "Test string 4" dsa.Put(@rgidx(0), bs4) ' // Get the value dsa.Get(@rgidx(0), bsOut) print bsOut

Reference

  • Include file DSafeArray.inc
  • Defined in AfxNova/DSafeArray.inc:1185
  • Documented in COM/DSAFEARRAY Class.md
  • Topic: DSAFEARRAY Class