Help Center

DSAFEARRAY.CreateVectormethod

Creates a one-dimensional safe array from the given VARTYPE, lower bound and number elements.

COMmethodDSafeArray.incdocumented

Syntax

FUNCTION CreateVector (BYVAL vt AS VARTYPE, BYVAL cElements AS ULONG, BYVAL lLBound AS LONG) AS HRESULT

Parameters

NameDescription
vtThe base type of the array (the VARTYPE of each element of the array). The VARTYPE is restricted to a subset of the variant types. Neither the VT_ARRAY nor the VT_BYREF flag can be set. VT_EMPTY and VT_NULL are not valid base types for the array. All other types are legal.
cElementsThe number of elements in the array.
lLBoundThe lower bound for the array. Can be negative.

Return value

S_OK (0) on success or an HRESULT code on failure.

Description

Creates a fixed size safe array from the given VARTYPE, lower bound and number of elements.

Remarks

CreateVector allocates a single block of memory containing a SAFEARRAY structure for a single-dimension array (24 bytes), immediately followed by the array data. All of the existing safe array functions work correctly for safe arrays that are allocated with CreateVector.

A safe array created with CreateVector is allocated as a single block of memory. Both the SafeArray descriptor and the array data block are allocated contiguously in one allocation, which speeds up array allocation. However, a user can allocate the descriptor and data area separately using the SafeArrayAllocDescriptor and SafeArrayAllocData* calls.

Example

DIM dsa AS DSAFEARRAY dsa.CreateVector(VT_VARIANT, 1000, 1) FOR i AS LONG = 1 TO 1000 dsa.PutVar(i, "Test string " & WSTR(i)) NEXT

Reference

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