1999-01-24 19:52:55 +01:00
|
|
|
/*************************************************************************
|
2003-12-15 22:08:42 +01:00
|
|
|
* OLE Automation - SafeArray
|
1999-01-24 19:52:55 +01:00
|
|
|
*
|
2003-12-15 22:08:42 +01:00
|
|
|
* This file contains the implementation of the SafeArray functions.
|
1999-01-24 19:52:55 +01:00
|
|
|
*
|
|
|
|
* Copyright 1999 Sylvain St-Germain
|
2003-12-30 20:06:41 +01:00
|
|
|
* Copyright 2002-2003 Marcus Meissner
|
2003-12-15 22:08:42 +01:00
|
|
|
* Copyright 2003 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-01-03 00:13:56 +01:00
|
|
|
/* Memory Layout of a SafeArray:
|
|
|
|
*
|
|
|
|
* -0x10: start of memory.
|
2003-12-15 22:08:42 +01:00
|
|
|
* -0x10: GUID for VT_DISPATCH and VT_UNKNOWN safearrays (if FADF_HAVEIID)
|
2003-01-03 00:13:56 +01:00
|
|
|
* -0x04: DWORD varianttype; (for all others, except VT_RECORD) (if FADF_HAVEVARTYPE)
|
2003-12-15 22:08:42 +01:00
|
|
|
* -0x4: IRecordInfo* iface; (if FADF_RECORD, for VT_RECORD (can be NULL))
|
2003-01-03 00:13:56 +01:00
|
|
|
* 0x00: SAFEARRAY,
|
|
|
|
* 0x10: SAFEARRAYBOUNDS[0...]
|
|
|
|
*/
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2004-02-27 22:32:54 +01:00
|
|
|
#include <string.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
1999-01-24 19:52:55 +01:00
|
|
|
#include <stdio.h>
|
2004-08-11 21:43:45 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
1999-03-14 17:35:05 +01:00
|
|
|
#include "windef.h"
|
1999-02-28 20:14:33 +01:00
|
|
|
#include "winerror.h"
|
|
|
|
#include "winbase.h"
|
2003-12-15 22:08:42 +01:00
|
|
|
#include "variant.h"
|
2004-08-22 23:38:46 +02:00
|
|
|
#include "wine/debug.h"
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2004-07-04 02:09:11 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(variant);
|
1999-04-19 16:56:29 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/************************************************************************
|
|
|
|
* SafeArray {OLEAUT32}
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The SafeArray data type provides the underlying interface for Ole
|
|
|
|
* Automations arrays, used for example to represent array types in
|
|
|
|
* Visual Basic(tm) and to gather user defined parameters for invocation through
|
|
|
|
* an IDispatch interface.
|
|
|
|
*
|
|
|
|
* Safe arrays provide bounds checking and automatically manage the data
|
|
|
|
* types they contain, for example handing reference counting and copying
|
|
|
|
* of interface pointers. User defined types can be stored in arrays
|
|
|
|
* using the IRecordInfo interface.
|
|
|
|
*
|
|
|
|
* There are two types of SafeArray, normal and vectors. Normal arrays can have
|
2004-03-31 22:06:10 +02:00
|
|
|
* multiple dimensions and the data for the array is allocated separately from
|
|
|
|
* the array header. This is the most flexible type of array. Vectors, on the
|
2003-12-15 22:08:42 +01:00
|
|
|
* other hand, are fixed in size and consist of a single allocated block, and a
|
|
|
|
* single dimension.
|
|
|
|
*
|
|
|
|
* DATATYPES
|
|
|
|
* The following types of data can be stored within a SafeArray.
|
|
|
|
* Numeric:
|
|
|
|
*| VT_I1, VT_UI1, VT_I2, VT_UI2, VT_I4, VT_UI4, VT_I8, VT_UI8, VT_INT, VT_UINT,
|
|
|
|
*| VT_R4, VT_R8, VT_CY, VT_DECIMAL
|
|
|
|
* Interfaces:
|
|
|
|
*| VT_DISPATCH, VT_UNKNOWN, VT_RECORD
|
|
|
|
* Other:
|
|
|
|
*| VT_VARIANT, VT_INT_PTR, VT_UINT_PTR, VT_BOOL, VT_ERROR, VT_DATE, VT_BSTR
|
|
|
|
*
|
|
|
|
* FUNCTIONS
|
|
|
|
* BstrFromVector()
|
|
|
|
* VectorFromBstr()
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Undocumented hidden space before the start of a SafeArray descriptor */
|
|
|
|
#define SAFEARRAY_HIDDEN_SIZE sizeof(GUID)
|
|
|
|
|
2014-01-08 18:39:42 +01:00
|
|
|
/* features listed here are not propagated to newly created array or data copy
|
|
|
|
created with SafeArrayCopy()/SafeArrayCopyData() */
|
|
|
|
static const USHORT ignored_copy_features =
|
|
|
|
FADF_AUTO |
|
|
|
|
FADF_STATIC |
|
|
|
|
FADF_EMBEDDED |
|
|
|
|
FADF_FIXEDSIZE |
|
|
|
|
FADF_CREATEVECTOR;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/* Allocate memory */
|
2015-01-06 10:45:16 +01:00
|
|
|
static inline void* SAFEARRAY_Malloc(ULONG size)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2015-01-06 10:45:16 +01:00
|
|
|
void *ret = CoTaskMemAlloc(size);
|
|
|
|
if (ret)
|
|
|
|
memset(ret, 0, size);
|
|
|
|
return ret;
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Free memory */
|
2015-01-06 10:45:16 +01:00
|
|
|
static inline void SAFEARRAY_Free(void *ptr)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2015-01-06 10:45:16 +01:00
|
|
|
CoTaskMemFree(ptr);
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the size of a supported VT type (0 means unsupported) */
|
|
|
|
static DWORD SAFEARRAY_GetVTSize(VARTYPE vt)
|
|
|
|
{
|
|
|
|
switch (vt)
|
|
|
|
{
|
|
|
|
case VT_I1:
|
|
|
|
case VT_UI1: return sizeof(BYTE);
|
|
|
|
case VT_BOOL:
|
|
|
|
case VT_I2:
|
|
|
|
case VT_UI2: return sizeof(SHORT);
|
|
|
|
case VT_I4:
|
|
|
|
case VT_UI4:
|
|
|
|
case VT_R4:
|
|
|
|
case VT_ERROR: return sizeof(LONG);
|
|
|
|
case VT_R8:
|
|
|
|
case VT_I8:
|
|
|
|
case VT_UI8: return sizeof(LONG64);
|
|
|
|
case VT_INT:
|
|
|
|
case VT_UINT: return sizeof(INT);
|
|
|
|
case VT_INT_PTR:
|
|
|
|
case VT_UINT_PTR: return sizeof(UINT_PTR);
|
|
|
|
case VT_CY: return sizeof(CY);
|
|
|
|
case VT_DATE: return sizeof(DATE);
|
|
|
|
case VT_BSTR: return sizeof(BSTR);
|
|
|
|
case VT_DISPATCH: return sizeof(LPDISPATCH);
|
|
|
|
case VT_VARIANT: return sizeof(VARIANT);
|
|
|
|
case VT_UNKNOWN: return sizeof(LPUNKNOWN);
|
|
|
|
case VT_DECIMAL: return sizeof(DECIMAL);
|
|
|
|
/* Note: Return a non-zero size to indicate vt is valid. The actual size
|
|
|
|
* of a UDT is taken from the result of IRecordInfo_GetSize().
|
|
|
|
*/
|
|
|
|
case VT_RECORD: return 32;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the hidden data for an array */
|
|
|
|
static inline void SAFEARRAY_SetHiddenDWORD(SAFEARRAY* psa, DWORD dw)
|
|
|
|
{
|
|
|
|
/* Implementation data is stored in the 4 bytes before the header */
|
|
|
|
LPDWORD lpDw = (LPDWORD)psa;
|
|
|
|
lpDw[-1] = dw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the hidden data from an array */
|
|
|
|
static inline DWORD SAFEARRAY_GetHiddenDWORD(SAFEARRAY* psa)
|
|
|
|
{
|
|
|
|
LPDWORD lpDw = (LPDWORD)psa;
|
|
|
|
return lpDw[-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the number of cells in a SafeArray */
|
|
|
|
static ULONG SAFEARRAY_GetCellCount(const SAFEARRAY *psa)
|
|
|
|
{
|
2005-01-03 15:50:12 +01:00
|
|
|
const SAFEARRAYBOUND* psab = psa->rgsabound;
|
2003-12-15 22:08:42 +01:00
|
|
|
USHORT cCount = psa->cDims;
|
|
|
|
ULONG ulNumCells = 1;
|
2001-09-21 23:01:31 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
while (cCount--)
|
|
|
|
{
|
2003-12-30 20:06:41 +01:00
|
|
|
/* This is a valid bordercase. See testcases. -Marcus */
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psab->cElements)
|
2003-12-30 20:06:41 +01:00
|
|
|
return 0;
|
2003-12-15 22:08:42 +01:00
|
|
|
ulNumCells *= psab->cElements;
|
|
|
|
psab++;
|
|
|
|
}
|
|
|
|
return ulNumCells;
|
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/* Allocate a descriptor for an array */
|
|
|
|
static HRESULT SAFEARRAY_AllocDescriptor(ULONG ulSize, SAFEARRAY **ppsaOut)
|
|
|
|
{
|
2011-01-14 21:30:17 +01:00
|
|
|
char *ptr = SAFEARRAY_Malloc(ulSize + SAFEARRAY_HIDDEN_SIZE);
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2011-01-14 21:30:17 +01:00
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
*ppsaOut = NULL;
|
2014-02-25 05:42:49 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2011-01-14 21:30:17 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2011-01-14 21:30:17 +01:00
|
|
|
*ppsaOut = (SAFEARRAY*)(ptr + SAFEARRAY_HIDDEN_SIZE);
|
2003-12-15 22:08:42 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the features of an array */
|
|
|
|
static void SAFEARRAY_SetFeatures(VARTYPE vt, SAFEARRAY *psa)
|
|
|
|
{
|
|
|
|
/* Set the IID if we have one, otherwise set the type */
|
|
|
|
if (vt == VT_DISPATCH)
|
|
|
|
{
|
|
|
|
psa->fFeatures = FADF_HAVEIID;
|
|
|
|
SafeArraySetIID(psa, &IID_IDispatch);
|
|
|
|
}
|
|
|
|
else if (vt == VT_UNKNOWN)
|
|
|
|
{
|
|
|
|
psa->fFeatures = FADF_HAVEIID;
|
|
|
|
SafeArraySetIID(psa, &IID_IUnknown);
|
|
|
|
}
|
|
|
|
else if (vt == VT_RECORD)
|
|
|
|
psa->fFeatures = FADF_RECORD;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
psa->fFeatures = FADF_HAVEVARTYPE;
|
|
|
|
SAFEARRAY_SetHiddenDWORD(psa, vt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create an array */
|
2007-07-02 22:14:59 +02:00
|
|
|
static SAFEARRAY* SAFEARRAY_Create(VARTYPE vt, UINT cDims, const SAFEARRAYBOUND *rgsabound, ULONG ulSize)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
|
|
|
SAFEARRAY *psa = NULL;
|
2008-11-02 19:46:53 +01:00
|
|
|
unsigned int i;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
if (!rgsabound)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (SUCCEEDED(SafeArrayAllocDescriptorEx(vt, cDims, &psa)))
|
|
|
|
{
|
|
|
|
switch (vt)
|
|
|
|
{
|
|
|
|
case VT_BSTR: psa->fFeatures |= FADF_BSTR; break;
|
|
|
|
case VT_UNKNOWN: psa->fFeatures |= FADF_UNKNOWN; break;
|
|
|
|
case VT_DISPATCH: psa->fFeatures |= FADF_DISPATCH; break;
|
|
|
|
case VT_VARIANT: psa->fFeatures |= FADF_VARIANT; break;
|
|
|
|
}
|
|
|
|
|
2006-06-04 13:43:13 +02:00
|
|
|
for (i = 0; i < cDims; i++)
|
|
|
|
memcpy(psa->rgsabound + i, rgsabound + cDims - 1 - i, sizeof(SAFEARRAYBOUND));
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
if (ulSize)
|
|
|
|
psa->cbElements = ulSize;
|
|
|
|
|
2006-12-27 20:14:38 +01:00
|
|
|
if (!psa->cbElements || FAILED(SafeArrayAllocData(psa)))
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
|
|
|
SafeArrayDestroyDescriptor(psa);
|
|
|
|
psa = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return psa;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create an array as a vector */
|
|
|
|
static SAFEARRAY* SAFEARRAY_CreateVector(VARTYPE vt, LONG lLbound, ULONG cElements, ULONG ulSize)
|
|
|
|
{
|
|
|
|
SAFEARRAY *psa = NULL;
|
|
|
|
|
2003-12-30 20:06:41 +01:00
|
|
|
if (ulSize || (vt == VT_RECORD))
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
|
|
|
/* Allocate the header and data together */
|
|
|
|
if (SUCCEEDED(SAFEARRAY_AllocDescriptor(sizeof(SAFEARRAY) + ulSize * cElements, &psa)))
|
|
|
|
{
|
|
|
|
SAFEARRAY_SetFeatures(vt, psa);
|
|
|
|
|
|
|
|
psa->cDims = 1;
|
|
|
|
psa->fFeatures |= FADF_CREATEVECTOR;
|
|
|
|
psa->pvData = &psa[1]; /* Data follows the header */
|
|
|
|
psa->cbElements = ulSize;
|
|
|
|
psa->rgsabound[0].cElements = cElements;
|
|
|
|
psa->rgsabound[0].lLbound = lLbound;
|
|
|
|
|
|
|
|
switch (vt)
|
|
|
|
{
|
|
|
|
case VT_BSTR: psa->fFeatures |= FADF_BSTR; break;
|
|
|
|
case VT_UNKNOWN: psa->fFeatures |= FADF_UNKNOWN; break;
|
|
|
|
case VT_DISPATCH: psa->fFeatures |= FADF_DISPATCH; break;
|
|
|
|
case VT_VARIANT: psa->fFeatures |= FADF_VARIANT; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return psa;
|
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/* Free data items in an array */
|
|
|
|
static HRESULT SAFEARRAY_DestroyData(SAFEARRAY *psa, ULONG ulStartCell)
|
|
|
|
{
|
|
|
|
if (psa->pvData && !(psa->fFeatures & FADF_DATADELETED))
|
|
|
|
{
|
|
|
|
ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-30 20:06:41 +01:00
|
|
|
if (ulStartCell > ulCellCount) {
|
2018-11-29 13:19:09 +01:00
|
|
|
FIXME("unexpected ulCellCount %d, start %d\n",ulCellCount,ulStartCell);
|
2003-12-15 22:08:42 +01:00
|
|
|
return E_UNEXPECTED;
|
2003-12-30 20:06:41 +01:00
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
ulCellCount -= ulStartCell;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
|
|
|
|
{
|
2006-06-09 12:02:04 +02:00
|
|
|
LPUNKNOWN *lpUnknown = (LPUNKNOWN *)psa->pvData + ulStartCell;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
|
|
|
if (*lpUnknown)
|
|
|
|
IUnknown_Release(*lpUnknown);
|
|
|
|
lpUnknown++;
|
|
|
|
}
|
|
|
|
}
|
2014-02-18 07:59:31 +01:00
|
|
|
else if (psa->fFeatures & FADF_RECORD)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
|
|
|
IRecordInfo *lpRecInfo;
|
|
|
|
|
|
|
|
if (SUCCEEDED(SafeArrayGetRecordInfo(psa, &lpRecInfo)))
|
|
|
|
{
|
2009-02-09 09:45:52 +01:00
|
|
|
PBYTE pRecordData = psa->pvData;
|
2003-12-15 22:08:42 +01:00
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
|
|
|
IRecordInfo_RecordClear(lpRecInfo, pRecordData);
|
|
|
|
pRecordData += psa->cbElements;
|
|
|
|
}
|
|
|
|
IRecordInfo_Release(lpRecInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_BSTR)
|
|
|
|
{
|
2006-06-09 12:02:04 +02:00
|
|
|
BSTR* lpBstr = (BSTR*)psa->pvData + ulStartCell;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
2008-09-24 23:04:49 +02:00
|
|
|
SysFreeString(*lpBstr);
|
2003-12-15 22:08:42 +01:00
|
|
|
lpBstr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_VARIANT)
|
|
|
|
{
|
2006-06-09 12:02:04 +02:00
|
|
|
VARIANT* lpVariant = (VARIANT*)psa->pvData + ulStartCell;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
2004-09-20 21:11:48 +02:00
|
|
|
HRESULT hRet = VariantClear(lpVariant);
|
|
|
|
|
|
|
|
if (FAILED(hRet)) FIXME("VariantClear of element failed!\n");
|
2003-12-15 22:08:42 +01:00
|
|
|
lpVariant++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2014-02-18 07:59:31 +01:00
|
|
|
/* Copy data items from one array to another. Destination data is freed before copy. */
|
2003-12-15 22:08:42 +01:00
|
|
|
static HRESULT SAFEARRAY_CopyData(SAFEARRAY *psa, SAFEARRAY *dest)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2014-02-18 07:59:31 +01:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2005-12-12 11:52:51 +01:00
|
|
|
if (!psa->pvData)
|
|
|
|
return S_OK;
|
2014-02-18 07:59:31 +01:00
|
|
|
|
|
|
|
if (!dest->pvData || psa->fFeatures & FADF_DATADELETED)
|
2003-12-15 22:08:42 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
|
1999-03-10 14:25:27 +01:00
|
|
|
|
2014-01-08 18:39:42 +01:00
|
|
|
dest->fFeatures = (dest->fFeatures & FADF_CREATEVECTOR) | (psa->fFeatures & ~ignored_copy_features);
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
if (psa->fFeatures & FADF_VARIANT)
|
|
|
|
{
|
2014-02-18 07:59:31 +01:00
|
|
|
VARIANT *src_var = psa->pvData;
|
|
|
|
VARIANT *dest_var = dest->pvData;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
2004-09-20 21:11:48 +02:00
|
|
|
HRESULT hRet;
|
|
|
|
|
2014-02-18 07:59:31 +01:00
|
|
|
/* destination is cleared automatically */
|
|
|
|
hRet = VariantCopy(dest_var, src_var);
|
|
|
|
if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%08x, element %u\n", hRet, ulCellCount);
|
|
|
|
src_var++;
|
|
|
|
dest_var++;
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_BSTR)
|
|
|
|
{
|
2014-02-18 07:59:31 +01:00
|
|
|
BSTR *src_bstr = psa->pvData;
|
|
|
|
BSTR *dest_bstr = dest->pvData;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
2014-02-18 07:59:31 +01:00
|
|
|
SysFreeString(*dest_bstr);
|
|
|
|
if (*src_bstr)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2014-02-18 07:59:31 +01:00
|
|
|
*dest_bstr = SysAllocStringByteLen((char*)*src_bstr, SysStringByteLen(*src_bstr));
|
|
|
|
if (!*dest_bstr)
|
2003-12-15 22:08:42 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
else
|
2014-02-18 07:59:31 +01:00
|
|
|
*dest_bstr = NULL;
|
|
|
|
src_bstr++;
|
|
|
|
dest_bstr++;
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 07:59:31 +01:00
|
|
|
else if (psa->fFeatures & FADF_RECORD)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2014-02-18 07:59:31 +01:00
|
|
|
BYTE *dest_data = dest->pvData;
|
|
|
|
BYTE *src_data = psa->pvData;
|
|
|
|
IRecordInfo *record;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2014-02-18 07:59:31 +01:00
|
|
|
SafeArrayGetRecordInfo(psa, &record);
|
|
|
|
while (ulCellCount--)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2014-02-18 07:59:31 +01:00
|
|
|
/* RecordCopy() clears destination record */
|
|
|
|
hr = IRecordInfo_RecordCopy(record, src_data, dest_data);
|
|
|
|
if (FAILED(hr)) break;
|
2014-02-24 05:15:59 +01:00
|
|
|
src_data += psa->cbElements;
|
|
|
|
dest_data += psa->cbElements;
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
|
2014-02-18 07:59:31 +01:00
|
|
|
SafeArraySetRecordInfo(dest, record);
|
2014-02-24 05:15:59 +01:00
|
|
|
/* This value is set to 32 bytes by default on descriptor creation,
|
|
|
|
update with actual structure size. */
|
|
|
|
dest->cbElements = psa->cbElements;
|
2014-02-18 07:59:31 +01:00
|
|
|
IRecordInfo_Release(record);
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2014-02-18 07:59:31 +01:00
|
|
|
IUnknown **dest_unk = dest->pvData;
|
|
|
|
IUnknown **src_unk = psa->pvData;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2014-02-18 07:59:31 +01:00
|
|
|
/* release old iface, addref new one */
|
|
|
|
while (ulCellCount--)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2014-02-18 07:59:31 +01:00
|
|
|
if (*dest_unk)
|
|
|
|
IUnknown_Release(*dest_unk);
|
|
|
|
*dest_unk = *src_unk;
|
|
|
|
if (*dest_unk)
|
|
|
|
IUnknown_AddRef(*dest_unk);
|
|
|
|
src_unk++;
|
|
|
|
dest_unk++;
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 07:59:31 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Copy the data over */
|
|
|
|
memcpy(dest->pvData, psa->pvData, ulCellCount * psa->cbElements);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (psa->fFeatures & FADF_HAVEIID)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
|
|
|
GUID guid;
|
|
|
|
SafeArrayGetIID(psa, &guid);
|
|
|
|
SafeArraySetIID(dest, &guid);
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_HAVEVARTYPE)
|
|
|
|
{
|
|
|
|
SAFEARRAY_SetHiddenDWORD(dest, SAFEARRAY_GetHiddenDWORD(psa));
|
|
|
|
}
|
|
|
|
}
|
2014-02-18 07:59:31 +01:00
|
|
|
|
|
|
|
return hr;
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
1999-03-10 14:25:27 +01:00
|
|
|
|
1999-01-24 19:52:55 +01:00
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayAllocDescriptor (OLEAUT32.36)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Allocate and initialise a descriptor for a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* cDims [I] Number of dimensions of the array
|
|
|
|
* ppsaOut [O] Destination for new descriptor
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ppsaOut is filled with a newly allocated descriptor.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayAllocDescriptor(UINT cDims, SAFEARRAY **ppsaOut)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
LONG allocSize;
|
2014-02-25 05:42:49 +01:00
|
|
|
HRESULT hr;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%d,%p)\n", cDims, ppsaOut);
|
|
|
|
|
|
|
|
if (!cDims || cDims >= 0x10000) /* Maximum 65535 dimensions */
|
2002-12-23 03:02:49 +01:00
|
|
|
return E_INVALIDARG;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2002-12-23 03:02:49 +01:00
|
|
|
if (!ppsaOut)
|
|
|
|
return E_POINTER;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/* We need enough space for the header and its bounds */
|
|
|
|
allocSize = sizeof(SAFEARRAY) + sizeof(SAFEARRAYBOUND) * (cDims - 1);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2014-02-25 05:42:49 +01:00
|
|
|
hr = SAFEARRAY_AllocDescriptor(allocSize, ppsaOut);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
(*ppsaOut)->cDims = cDims;
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%d): %u bytes allocated for descriptor.\n", cDims, allocSize);
|
2003-12-15 22:08:42 +01:00
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
2002-01-29 03:44:44 +01:00
|
|
|
/*************************************************************************
|
2002-07-19 02:30:16 +02:00
|
|
|
* SafeArrayAllocDescriptorEx (OLEAUT32.41)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Allocate and initialise a descriptor for a SafeArray of a given type.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* vt [I] The type of items to store in the array
|
|
|
|
* cDims [I] Number of dimensions of the array
|
|
|
|
* ppsaOut [O] Destination for new descriptor
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ppsaOut is filled with a newly allocated descriptor.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
2008-04-11 01:24:54 +02:00
|
|
|
* - This function does not check that vt is an allowed VARTYPE.
|
2003-12-15 22:08:42 +01:00
|
|
|
* - Unlike SafeArrayAllocDescriptor(), vt is associated with the array.
|
|
|
|
* See SafeArray.
|
2002-01-29 03:44:44 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayAllocDescriptorEx(VARTYPE vt, UINT cDims, SAFEARRAY **ppsaOut)
|
2002-01-29 03:44:44 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
ULONG cbElements;
|
2014-02-25 05:42:49 +01:00
|
|
|
HRESULT hRet;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
TRACE("(%d->%s,%d,%p)\n", vt, debugstr_vt(vt), cDims, ppsaOut);
|
|
|
|
|
|
|
|
cbElements = SAFEARRAY_GetVTSize(vt);
|
|
|
|
if (!cbElements)
|
|
|
|
WARN("Creating a descriptor with an invalid VARTYPE!\n");
|
|
|
|
|
|
|
|
hRet = SafeArrayAllocDescriptor(cDims, ppsaOut);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
|
|
|
SAFEARRAY_SetFeatures(vt, *ppsaOut);
|
|
|
|
(*ppsaOut)->cbElements = cbElements;
|
2003-01-03 00:13:56 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
return hRet;
|
2002-01-29 03:44:44 +01:00
|
|
|
}
|
|
|
|
|
1999-01-24 19:52:55 +01:00
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayAllocData (OLEAUT32.37)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Allocate the data area of a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] SafeArray to allocate the data area of.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The data area is allocated and initialised.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayAllocData(SAFEARRAY *psa)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT hRet = E_INVALIDARG;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", psa);
|
|
|
|
|
|
|
|
if (psa)
|
|
|
|
{
|
|
|
|
ULONG ulSize = SAFEARRAY_GetCellCount(psa);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2006-12-27 20:14:38 +01:00
|
|
|
psa->pvData = SAFEARRAY_Malloc(ulSize * psa->cbElements);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2006-12-27 20:14:38 +01:00
|
|
|
if (psa->pvData)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2006-12-27 20:14:38 +01:00
|
|
|
hRet = S_OK;
|
|
|
|
TRACE("%u bytes allocated for data at %p (%u objects).\n",
|
|
|
|
ulSize * psa->cbElements, psa->pvData, ulSize);
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
2006-12-27 20:14:38 +01:00
|
|
|
else
|
|
|
|
hRet = E_OUTOFMEMORY;
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
return hRet;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayCreate (OLEAUT32.15)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Create a new SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* vt [I] Type to store in the safe array
|
|
|
|
* cDims [I] Number of array dimensions
|
|
|
|
* rgsabound [I] Bounds of the array dimensions
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A pointer to a new array object.
|
|
|
|
* Failure: NULL, if any parameter is invalid or memory allocation fails.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Win32 allows arrays with 0 sized dimensions. This bug is not reproduced
|
|
|
|
* in the Wine implementation.
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
SAFEARRAY* WINAPI SafeArrayCreate(VARTYPE vt, UINT cDims, SAFEARRAYBOUND *rgsabound)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%d->%s,%d,%p)\n", vt, debugstr_vt(vt), cDims, rgsabound);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (vt == VT_RECORD)
|
1999-01-24 19:52:55 +01:00
|
|
|
return NULL;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
return SAFEARRAY_Create(vt, cDims, rgsabound, 0);
|
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* SafeArrayCreateEx (OLEAUT32.15)
|
|
|
|
*
|
|
|
|
* Create a new SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* vt [I] Type to store in the safe array
|
|
|
|
* cDims [I] Number of array dimensions
|
|
|
|
* rgsabound [I] Bounds of the array dimensions
|
|
|
|
* pvExtra [I] Extra data
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A pointer to a new array object.
|
|
|
|
* Failure: NULL, if any parameter is invalid or memory allocation fails.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
|
|
|
*/
|
|
|
|
SAFEARRAY* WINAPI SafeArrayCreateEx(VARTYPE vt, UINT cDims, SAFEARRAYBOUND *rgsabound, LPVOID pvExtra)
|
|
|
|
{
|
|
|
|
ULONG ulSize = 0;
|
2009-02-09 09:45:52 +01:00
|
|
|
IRecordInfo* iRecInfo = pvExtra;
|
2003-12-15 22:08:42 +01:00
|
|
|
SAFEARRAY* psa;
|
|
|
|
|
|
|
|
TRACE("(%d->%s,%d,%p,%p)\n", vt, debugstr_vt(vt), cDims, rgsabound, pvExtra);
|
|
|
|
|
|
|
|
if (vt == VT_RECORD)
|
|
|
|
{
|
|
|
|
if (!iRecInfo)
|
|
|
|
return NULL;
|
|
|
|
IRecordInfo_GetSize(iRecInfo, &ulSize);
|
2003-01-03 00:13:56 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
psa = SAFEARRAY_Create(vt, cDims, rgsabound, ulSize);
|
|
|
|
|
|
|
|
if (pvExtra)
|
|
|
|
{
|
|
|
|
switch(vt)
|
|
|
|
{
|
|
|
|
case VT_RECORD:
|
|
|
|
SafeArraySetRecordInfo(psa, pvExtra);
|
|
|
|
break;
|
|
|
|
case VT_UNKNOWN:
|
|
|
|
case VT_DISPATCH:
|
|
|
|
SafeArraySetIID(psa, pvExtra);
|
|
|
|
break;
|
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
return psa;
|
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/************************************************************************
|
|
|
|
* SafeArrayCreateVector (OLEAUT32.411)
|
|
|
|
*
|
2005-03-23 14:15:18 +01:00
|
|
|
* Create a one dimensional, contiguous SafeArray.
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* vt [I] Type to store in the safe array
|
|
|
|
* lLbound [I] Lower bound of the array
|
|
|
|
* cElements [I] Number of elements in the array
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A pointer to a new array object.
|
|
|
|
* Failure: NULL, if any parameter is invalid or memory allocation fails.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
|
|
|
*/
|
|
|
|
SAFEARRAY* WINAPI SafeArrayCreateVector(VARTYPE vt, LONG lLbound, ULONG cElements)
|
|
|
|
{
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%d->%s,%d,%d\n", vt, debugstr_vt(vt), lLbound, cElements);
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
if (vt == VT_RECORD)
|
1999-01-24 19:52:55 +01:00
|
|
|
return NULL;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
return SAFEARRAY_CreateVector(vt, lLbound, cElements, SAFEARRAY_GetVTSize(vt));
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* SafeArrayCreateVectorEx (OLEAUT32.411)
|
|
|
|
*
|
2005-03-23 14:15:18 +01:00
|
|
|
* Create a one dimensional, contiguous SafeArray.
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* vt [I] Type to store in the safe array
|
|
|
|
* lLbound [I] Lower bound of the array
|
|
|
|
* cElements [I] Number of elements in the array
|
|
|
|
* pvExtra [I] Extra data
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: A pointer to a new array object.
|
|
|
|
* Failure: NULL, if any parameter is invalid or memory allocation fails.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
|
|
|
*/
|
|
|
|
SAFEARRAY* WINAPI SafeArrayCreateVectorEx(VARTYPE vt, LONG lLbound, ULONG cElements, LPVOID pvExtra)
|
|
|
|
{
|
|
|
|
ULONG ulSize;
|
2009-02-09 09:45:52 +01:00
|
|
|
IRecordInfo* iRecInfo = pvExtra;
|
2003-12-15 22:08:42 +01:00
|
|
|
SAFEARRAY* psa;
|
|
|
|
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%d->%s,%d,%d,%p\n", vt, debugstr_vt(vt), lLbound, cElements, pvExtra);
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
if (vt == VT_RECORD)
|
|
|
|
{
|
|
|
|
if (!iRecInfo)
|
|
|
|
return NULL;
|
|
|
|
IRecordInfo_GetSize(iRecInfo, &ulSize);
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
else
|
|
|
|
ulSize = SAFEARRAY_GetVTSize(vt);
|
|
|
|
|
|
|
|
psa = SAFEARRAY_CreateVector(vt, lLbound, cElements, ulSize);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (pvExtra)
|
|
|
|
{
|
|
|
|
switch(vt)
|
|
|
|
{
|
|
|
|
case VT_RECORD:
|
|
|
|
SafeArraySetRecordInfo(psa, iRecInfo);
|
|
|
|
break;
|
|
|
|
case VT_UNKNOWN:
|
|
|
|
case VT_DISPATCH:
|
|
|
|
SafeArraySetIID(psa, pvExtra);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return psa;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayDestroyDescriptor (OLEAUT32.38)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Destroy a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] SafeArray to destroy.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The resources used by the array are freed.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayDestroyDescriptor(SAFEARRAY *psa)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p)\n", psa);
|
|
|
|
|
|
|
|
if (psa)
|
|
|
|
{
|
|
|
|
LPVOID lpv = (char*)psa - SAFEARRAY_HIDDEN_SIZE;
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psa->cLocks)
|
|
|
|
return DISP_E_ARRAYISLOCKED; /* Can't destroy a locked array */
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psa->fFeatures & FADF_RECORD)
|
|
|
|
SafeArraySetRecordInfo(psa, NULL);
|
|
|
|
|
|
|
|
if (psa->fFeatures & FADF_CREATEVECTOR &&
|
|
|
|
!(psa->fFeatures & FADF_DATADELETED))
|
|
|
|
SAFEARRAY_DestroyData(psa, 0); /* Data not previously deleted */
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2015-01-06 10:45:16 +01:00
|
|
|
SAFEARRAY_Free(lpv);
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayLock (OLEAUT32.21)
|
1999-01-24 19:52:55 +01:00
|
|
|
*
|
2003-12-15 22:08:42 +01:00
|
|
|
* Increment the lock counter of a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [O] SafeArray to lock
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The array lock is incremented.
|
|
|
|
* Failure: E_INVALIDARG if psa is NULL, or E_UNEXPECTED if too many locks
|
|
|
|
* are held on the array at once.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* In Win32 these locks are not thread safe.
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayLock(SAFEARRAY *psa)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
ULONG ulLocks;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", psa);
|
|
|
|
|
|
|
|
if (!psa)
|
1999-01-24 19:52:55 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2005-08-08 20:38:29 +02:00
|
|
|
ulLocks = InterlockedIncrement( (LONG*) &psa->cLocks);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (ulLocks > 0xffff) /* Maximum of 16384 locks at a time */
|
|
|
|
{
|
|
|
|
WARN("Out of locks!\n");
|
2005-08-08 20:38:29 +02:00
|
|
|
InterlockedDecrement( (LONG*) &psa->cLocks);
|
2003-12-15 22:08:42 +01:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayUnlock (OLEAUT32.22)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Decrement the lock counter of a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [O] SafeArray to unlock
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The array lock is decremented.
|
|
|
|
* Failure: E_INVALIDARG if psa is NULL, or E_UNEXPECTED if no locks are
|
|
|
|
* held on the array.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayUnlock(SAFEARRAY *psa)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p)\n", psa);
|
|
|
|
|
|
|
|
if (!psa)
|
1999-01-24 19:52:55 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2008-01-15 22:49:14 +01:00
|
|
|
if (InterlockedDecrement( (LONG*) &psa->cLocks) < 0)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
|
|
|
WARN("Unlocked but no lock held!\n");
|
2005-08-08 20:38:29 +02:00
|
|
|
InterlockedIncrement( (LONG*) &psa->cLocks);
|
2003-12-15 22:08:42 +01:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayPutElement (OLEAUT32.26)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Put an item into a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] SafeArray to insert into
|
|
|
|
* rgIndices [I] Indices to insert at
|
|
|
|
* pvData [I] Data to insert
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The item is inserted
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayPutElement(SAFEARRAY *psa, LONG *rgIndices, void *pvData)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT hRet;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p,%p)\n", psa, rgIndices, pvData);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psa || !rgIndices)
|
|
|
|
return E_INVALIDARG;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
hRet = SafeArrayLock(psa);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
|
|
|
PVOID lpvDest;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
hRet = SafeArrayPtrOfIndex(psa, rgIndices, &lpvDest);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
|
|
|
if (psa->fFeatures & FADF_VARIANT)
|
|
|
|
{
|
2009-02-09 09:45:52 +01:00
|
|
|
VARIANT* lpVariant = pvData;
|
|
|
|
VARIANT* lpDest = lpvDest;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2004-09-20 21:11:48 +02:00
|
|
|
hRet = VariantCopy(lpDest, lpVariant);
|
2006-10-12 20:57:10 +02:00
|
|
|
if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%x\n", hRet);
|
2001-09-21 23:01:31 +02:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
else if (psa->fFeatures & FADF_BSTR)
|
|
|
|
{
|
2003-12-30 20:06:41 +01:00
|
|
|
BSTR lpBstr = (BSTR)pvData;
|
2009-02-09 09:45:52 +01:00
|
|
|
BSTR* lpDest = lpvDest;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2008-09-24 23:04:49 +02:00
|
|
|
SysFreeString(*lpDest);
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2006-04-07 12:17:29 +02:00
|
|
|
*lpDest = SysAllocStringByteLen((char*)lpBstr, SysStringByteLen(lpBstr));
|
|
|
|
if (!*lpDest)
|
|
|
|
hRet = E_OUTOFMEMORY;
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
2014-02-24 05:15:21 +01:00
|
|
|
else if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2014-02-24 05:15:21 +01:00
|
|
|
IUnknown *lpUnknown = pvData;
|
|
|
|
IUnknown **lpDest = lpvDest;
|
|
|
|
|
|
|
|
if (lpUnknown)
|
|
|
|
IUnknown_AddRef(lpUnknown);
|
|
|
|
if (*lpDest)
|
|
|
|
IUnknown_Release(*lpDest);
|
|
|
|
*lpDest = lpUnknown;
|
2001-09-21 23:01:31 +02:00
|
|
|
}
|
2014-02-24 05:15:21 +01:00
|
|
|
else if (psa->fFeatures & FADF_RECORD)
|
|
|
|
{
|
|
|
|
IRecordInfo *record;
|
|
|
|
|
|
|
|
SafeArrayGetRecordInfo(psa, &record);
|
|
|
|
hRet = IRecordInfo_RecordCopy(record, pvData, lpvDest);
|
|
|
|
IRecordInfo_Release(record);
|
|
|
|
} else
|
|
|
|
/* Copy the data over */
|
|
|
|
memcpy(lpvDest, pvData, psa->cbElements);
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
SafeArrayUnlock(psa);
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
return hRet;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayGetElement (OLEAUT32.25)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Get an item from a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] SafeArray to get from
|
|
|
|
* rgIndices [I] Indices to get from
|
|
|
|
* pvData [O] Destination for data
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The item data is returned in pvData.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayGetElement(SAFEARRAY *psa, LONG *rgIndices, void *pvData)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT hRet;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p,%p)\n", psa, rgIndices, pvData);
|
|
|
|
|
|
|
|
if (!psa || !rgIndices || !pvData)
|
1999-01-24 19:52:55 +01:00
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
hRet = SafeArrayLock(psa);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
|
|
|
PVOID lpvSrc;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
hRet = SafeArrayPtrOfIndex(psa, rgIndices, &lpvSrc);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
|
|
|
if (psa->fFeatures & FADF_VARIANT)
|
|
|
|
{
|
2009-02-09 09:45:52 +01:00
|
|
|
VARIANT* lpVariant = lpvSrc;
|
|
|
|
VARIANT* lpDest = pvData;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-09-20 21:11:48 +02:00
|
|
|
/* The original content of pvData is ignored. */
|
|
|
|
V_VT(lpDest) = VT_EMPTY;
|
|
|
|
hRet = VariantCopy(lpDest, lpVariant);
|
2006-10-12 20:57:10 +02:00
|
|
|
if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%x\n", hRet);
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_BSTR)
|
|
|
|
{
|
2009-02-09 09:45:52 +01:00
|
|
|
BSTR* lpBstr = lpvSrc;
|
|
|
|
BSTR* lpDest = pvData;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
|
|
|
if (*lpBstr)
|
|
|
|
{
|
2004-01-09 01:58:01 +01:00
|
|
|
*lpDest = SysAllocStringByteLen((char*)*lpBstr, SysStringByteLen(*lpBstr));
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!*lpBstr)
|
|
|
|
hRet = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*lpDest = NULL;
|
|
|
|
}
|
2014-02-25 05:43:06 +01:00
|
|
|
else if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2014-02-25 05:43:06 +01:00
|
|
|
IUnknown **src_unk = lpvSrc;
|
|
|
|
IUnknown **dest_unk = pvData;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2014-02-25 05:43:06 +01:00
|
|
|
if (*src_unk)
|
|
|
|
IUnknown_AddRef(*src_unk);
|
|
|
|
*dest_unk = *src_unk;
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_RECORD)
|
|
|
|
{
|
|
|
|
IRecordInfo *record;
|
|
|
|
|
|
|
|
SafeArrayGetRecordInfo(psa, &record);
|
|
|
|
hRet = IRecordInfo_RecordCopy(record, lpvSrc, pvData);
|
|
|
|
IRecordInfo_Release(record);
|
|
|
|
}
|
|
|
|
else
|
2003-12-15 22:08:42 +01:00
|
|
|
/* Copy the data over */
|
|
|
|
memcpy(pvData, lpvSrc, psa->cbElements);
|
2001-09-21 23:01:31 +02:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
SafeArrayUnlock(psa);
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
return hRet;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayGetUBound (OLEAUT32.19)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Get the upper bound for a given SafeArray dimension
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to get dimension upper bound from
|
|
|
|
* nDim [I] The dimension number to get the upper bound of
|
|
|
|
* plUbound [O] Destination for the upper bound
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. plUbound contains the dimensions upper bound.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayGetUBound(SAFEARRAY *psa, UINT nDim, LONG *plUbound)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%d,%p)\n", psa, nDim, plUbound);
|
|
|
|
|
|
|
|
if (!psa || !plUbound)
|
1999-01-24 19:52:55 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2003-12-30 20:06:41 +01:00
|
|
|
if(!nDim || nDim > psa->cDims)
|
2000-12-21 21:18:18 +01:00
|
|
|
return DISP_E_BADINDEX;
|
|
|
|
|
2006-06-04 13:43:13 +02:00
|
|
|
*plUbound = psa->rgsabound[psa->cDims - nDim].lLbound +
|
|
|
|
psa->rgsabound[psa->cDims - nDim].cElements - 1;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayGetLBound (OLEAUT32.20)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Get the lower bound for a given SafeArray dimension
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to get dimension lower bound from
|
2011-08-02 22:20:32 +02:00
|
|
|
* nDim [I] The dimension number to get the lower bound of
|
2003-12-15 22:08:42 +01:00
|
|
|
* plLbound [O] Destination for the lower bound
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. plUbound contains the dimensions lower bound.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayGetLBound(SAFEARRAY *psa, UINT nDim, LONG *plLbound)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%d,%p)\n", psa, nDim, plLbound);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psa || !plLbound)
|
|
|
|
return E_INVALIDARG;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-30 20:06:41 +01:00
|
|
|
if(!nDim || nDim > psa->cDims)
|
2000-12-21 21:18:18 +01:00
|
|
|
return DISP_E_BADINDEX;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-06-04 13:43:13 +02:00
|
|
|
*plLbound = psa->rgsabound[psa->cDims - nDim].lLbound;
|
1999-01-24 19:52:55 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayGetDim (OLEAUT32.17)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Get the number of dimensions in a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to get the dimensions of
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The number of array dimensions in psa, or 0 if psa is NULL.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
UINT WINAPI SafeArrayGetDim(SAFEARRAY *psa)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p) returning %d\n", psa, psa ? psa->cDims : 0u);
|
2003-12-15 22:08:42 +01:00
|
|
|
return psa ? psa->cDims : 0;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayGetElemsize (OLEAUT32.18)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Get the size of an element in a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to get the element size from
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The size of a single element in psa, or 0 if psa is NULL.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
UINT WINAPI SafeArrayGetElemsize(SAFEARRAY *psa)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2006-10-12 20:57:10 +02:00
|
|
|
TRACE("(%p) returning %d\n", psa, psa ? psa->cbElements : 0u);
|
2003-12-15 22:08:42 +01:00
|
|
|
return psa ? psa->cbElements : 0;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayAccessData (OLEAUT32.23)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Lock a SafeArray and return a pointer to its data.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to get the data pointer from
|
|
|
|
* ppvData [O] Destination for the arrays data pointer
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ppvData contains the arrays data pointer, and the array
|
|
|
|
* is locked.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2014-02-25 05:42:49 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p)\n", psa, ppvData);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if(!psa || !ppvData)
|
1999-01-24 19:52:55 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2014-02-25 05:42:49 +01:00
|
|
|
hr = SafeArrayLock(psa);
|
|
|
|
*ppvData = SUCCEEDED(hr) ? psa->pvData : NULL;
|
|
|
|
|
|
|
|
return hr;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayUnaccessData (OLEAUT32.24)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Unlock a SafeArray after accessing its data.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to unlock
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The array is unlocked.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayUnaccessData(SAFEARRAY *psa)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p)\n", psa);
|
|
|
|
return SafeArrayUnlock(psa);
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2003-12-15 22:08:42 +01:00
|
|
|
* SafeArrayPtrOfIndex (OLEAUT32.148)
|
|
|
|
*
|
|
|
|
* Get the address of an item in a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to get the items address from
|
|
|
|
* rgIndices [I] Index of the item in the array
|
|
|
|
* ppvData [O] Destination for item address
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ppvData contains a pointer to the item.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* This function does not lock the array.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayPtrOfIndex(SAFEARRAY *psa, LONG *rgIndices, void **ppvData)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
USHORT dim;
|
|
|
|
ULONG cell = 0, dimensionSize = 1;
|
|
|
|
SAFEARRAYBOUND* psab;
|
|
|
|
LONG c1;
|
|
|
|
|
|
|
|
TRACE("(%p,%p,%p)\n", psa, rgIndices, ppvData);
|
|
|
|
|
|
|
|
/* The general formula for locating the cell number of an entry in an n
|
|
|
|
* dimensional array (where cn = coordinate in dimension dn) is:
|
|
|
|
*
|
|
|
|
* c1 + c2 * sizeof(d1) + c3 * sizeof(d2) ... + cn * sizeof(c(n-1))
|
|
|
|
*
|
|
|
|
* We calculate the size of the last dimension at each step through the
|
|
|
|
* dimensions to avoid recursing to calculate the last dimensions size.
|
|
|
|
*/
|
|
|
|
if (!psa || !rgIndices || !ppvData)
|
1999-01-24 19:52:55 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2006-06-04 13:43:13 +02:00
|
|
|
psab = psa->rgsabound + psa->cDims - 1;
|
2003-12-15 22:08:42 +01:00
|
|
|
c1 = *rgIndices++;
|
2002-12-12 23:59:07 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (c1 < psab->lLbound || c1 >= psab->lLbound + (LONG)psab->cElements)
|
|
|
|
return DISP_E_BADINDEX; /* Initial index out of bounds */
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
for (dim = 1; dim < psa->cDims; dim++)
|
|
|
|
{
|
|
|
|
dimensionSize *= psab->cElements;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2006-06-04 13:43:13 +02:00
|
|
|
psab--;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psab->cElements ||
|
|
|
|
*rgIndices < psab->lLbound ||
|
|
|
|
*rgIndices >= psab->lLbound + (LONG)psab->cElements)
|
|
|
|
return DISP_E_BADINDEX; /* Index out of bounds */
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
cell += (*rgIndices - psab->lLbound) * dimensionSize;
|
|
|
|
rgIndices++;
|
2001-09-21 23:01:31 +02:00
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2006-06-04 13:43:13 +02:00
|
|
|
cell += (c1 - psa->rgsabound[psa->cDims - 1].lLbound);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
*ppvData = (char*)psa->pvData + cell * psa->cbElements;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2001-09-21 23:01:31 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/************************************************************************
|
|
|
|
* SafeArrayDestroyData (OLEAUT32.39)
|
|
|
|
*
|
|
|
|
* Destroy the data associated with a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to delete the data from
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. All items and the item data are freed.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI SafeArrayDestroyData(SAFEARRAY *psa)
|
|
|
|
{
|
2014-02-25 05:42:49 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p)\n", psa);
|
|
|
|
|
|
|
|
if (!psa)
|
|
|
|
return E_INVALIDARG;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psa->cLocks)
|
2004-03-24 00:20:16 +01:00
|
|
|
return DISP_E_ARRAYISLOCKED; /* Can't delete a locked array */
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2006-06-09 12:02:04 +02:00
|
|
|
/* Delete the actual item data */
|
2014-02-25 05:42:49 +01:00
|
|
|
hr = SAFEARRAY_DestroyData(psa, 0);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2006-06-09 12:02:04 +02:00
|
|
|
if (psa->pvData)
|
|
|
|
{
|
|
|
|
if (psa->fFeatures & FADF_STATIC)
|
|
|
|
{
|
|
|
|
ZeroMemory(psa->pvData, SAFEARRAY_GetCellCount(psa) * psa->cbElements);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
/* If this is not a vector, free the data memory block */
|
|
|
|
if (!(psa->fFeatures & FADF_CREATEVECTOR))
|
|
|
|
{
|
2015-01-06 10:45:16 +01:00
|
|
|
SAFEARRAY_Free(psa->pvData);
|
2003-12-15 22:08:42 +01:00
|
|
|
psa->pvData = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
psa->fFeatures |= FADF_DATADELETED; /* Mark the data deleted */
|
1999-01-24 19:52:55 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayCopyData (OLEAUT32.412)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Copy all data from one SafeArray to another.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psaSource [I] Source for copy
|
|
|
|
* psaTarget [O] Destination for copy
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. psaTarget contains a copy of psaSource.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The two arrays must have the same number of dimensions and elements.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayCopyData(SAFEARRAY *psaSource, SAFEARRAY *psaTarget)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
int dim;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p)\n", psaSource, psaTarget);
|
|
|
|
|
|
|
|
if (!psaSource || !psaTarget ||
|
|
|
|
psaSource->cDims != psaTarget->cDims ||
|
|
|
|
psaSource->cbElements != psaTarget->cbElements)
|
1999-01-24 19:52:55 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/* Each dimension must be the same size */
|
|
|
|
for (dim = psaSource->cDims - 1; dim >= 0 ; dim--)
|
|
|
|
if (psaSource->rgsabound[dim].cElements !=
|
|
|
|
psaTarget->rgsabound[dim].cElements)
|
1999-01-24 19:52:55 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2014-01-08 18:39:42 +01:00
|
|
|
return SAFEARRAY_CopyData(psaSource, psaTarget);
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayDestroy (OLEAUT32.16)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Destroy a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to destroy
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. All resources used by the array are freed.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayDestroy(SAFEARRAY *psa)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p)\n", psa);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if(!psa)
|
2005-01-31 12:31:50 +01:00
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if(psa->cLocks > 0)
|
1999-01-24 19:52:55 +01:00
|
|
|
return DISP_E_ARRAYISLOCKED;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/* Native doesn't check to see if the free succeeds */
|
|
|
|
SafeArrayDestroyData(psa);
|
|
|
|
SafeArrayDestroyDescriptor(psa);
|
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayCopy (OLEAUT32.27)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Make a duplicate of a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Source for copy
|
|
|
|
* ppsaOut [O] Destination for new copy
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ppsaOut contains a copy of the array.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayCopy(SAFEARRAY *psa, SAFEARRAY **ppsaOut)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT hRet;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p)\n", psa, ppsaOut);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!ppsaOut)
|
|
|
|
return E_INVALIDARG;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
*ppsaOut = NULL;
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psa)
|
|
|
|
return S_OK; /* Handles copying of NULL arrays */
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2005-12-12 11:52:51 +01:00
|
|
|
if (!psa->cbElements)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psa->fFeatures & (FADF_RECORD|FADF_HAVEIID|FADF_HAVEVARTYPE))
|
|
|
|
{
|
|
|
|
VARTYPE vt;
|
2014-02-25 05:42:49 +01:00
|
|
|
|
|
|
|
hRet = SafeArrayGetVartype(psa, &vt);
|
|
|
|
if (SUCCEEDED(hRet))
|
2003-12-15 22:08:42 +01:00
|
|
|
hRet = SafeArrayAllocDescriptorEx(vt, psa->cDims, ppsaOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hRet = SafeArrayAllocDescriptor(psa->cDims, ppsaOut);
|
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
2014-01-08 18:39:42 +01:00
|
|
|
(*ppsaOut)->fFeatures = psa->fFeatures & ~ignored_copy_features;
|
2003-12-15 22:08:42 +01:00
|
|
|
(*ppsaOut)->cbElements = psa->cbElements;
|
2003-01-03 00:13:56 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
|
|
|
/* Copy dimension bounds */
|
|
|
|
memcpy((*ppsaOut)->rgsabound, psa->rgsabound, psa->cDims * sizeof(SAFEARRAYBOUND));
|
2000-06-18 21:29:40 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
(*ppsaOut)->pvData = SAFEARRAY_Malloc(SAFEARRAY_GetCellCount(psa) * psa->cbElements);
|
2014-02-25 05:42:49 +01:00
|
|
|
if (!(*ppsaOut)->pvData)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2014-02-25 05:42:49 +01:00
|
|
|
SafeArrayDestroyDescriptor(*ppsaOut);
|
|
|
|
*ppsaOut = NULL;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2014-02-25 05:42:49 +01:00
|
|
|
hRet = SAFEARRAY_CopyData(psa, *ppsaOut);
|
|
|
|
if (FAILED(hRet))
|
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
SAFEARRAY_Free((*ppsaOut)->pvData);
|
2014-02-25 05:42:49 +01:00
|
|
|
SafeArrayDestroyDescriptor(*ppsaOut);
|
|
|
|
*ppsaOut = NULL;
|
|
|
|
return hRet;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-25 05:42:49 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
return hRet;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SafeArrayRedim (OLEAUT32.40)
|
2003-12-15 22:08:42 +01:00
|
|
|
*
|
|
|
|
* Changes the characteristics of the last dimension of a SafeArray
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to change
|
|
|
|
* psabound [I] New bound details for the last dimension
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. psa is updated to reflect the new bounds.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayRedim(SAFEARRAY *psa, SAFEARRAYBOUND *psabound)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
SAFEARRAYBOUND *oldBounds;
|
2014-02-25 05:42:49 +01:00
|
|
|
HRESULT hr;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p)\n", psa, psabound);
|
|
|
|
|
2003-12-30 20:06:41 +01:00
|
|
|
if (!psa || psa->fFeatures & FADF_FIXEDSIZE || !psabound)
|
1999-01-24 19:52:55 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psa->cLocks > 0)
|
1999-01-24 19:52:55 +01:00
|
|
|
return DISP_E_ARRAYISLOCKED;
|
|
|
|
|
2014-02-25 05:42:49 +01:00
|
|
|
hr = SafeArrayLock(psa);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2006-06-04 13:43:13 +02:00
|
|
|
oldBounds = psa->rgsabound;
|
2003-12-15 22:08:42 +01:00
|
|
|
oldBounds->lLbound = psabound->lLbound;
|
2001-10-14 18:07:36 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psabound->cElements != oldBounds->cElements)
|
|
|
|
{
|
|
|
|
if (psabound->cElements < oldBounds->cElements)
|
|
|
|
{
|
|
|
|
/* Shorten the final dimension. */
|
2006-06-04 13:43:13 +02:00
|
|
|
ULONG ulStartCell = psabound->cElements *
|
|
|
|
(SAFEARRAY_GetCellCount(psa) / oldBounds->cElements);
|
2003-12-15 22:08:42 +01:00
|
|
|
SAFEARRAY_DestroyData(psa, ulStartCell);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Lengthen the final dimension */
|
|
|
|
ULONG ulOldSize, ulNewSize;
|
|
|
|
PVOID pvNewData;
|
|
|
|
|
2004-01-12 22:06:30 +01:00
|
|
|
ulOldSize = SAFEARRAY_GetCellCount(psa) * psa->cbElements;
|
2003-12-30 20:06:41 +01:00
|
|
|
if (ulOldSize)
|
|
|
|
ulNewSize = (ulOldSize / oldBounds->cElements) * psabound->cElements;
|
|
|
|
else {
|
|
|
|
int oldelems = oldBounds->cElements;
|
|
|
|
oldBounds->cElements = psabound->cElements;
|
2003-12-31 19:58:25 +01:00
|
|
|
ulNewSize = SAFEARRAY_GetCellCount(psa) * psa->cbElements;
|
2003-12-30 20:06:41 +01:00
|
|
|
oldBounds->cElements = oldelems;
|
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
|
2003-12-30 20:06:41 +01:00
|
|
|
if (!(pvNewData = SAFEARRAY_Malloc(ulNewSize)))
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
|
|
|
SafeArrayUnlock(psa);
|
2014-02-25 05:42:49 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
memcpy(pvNewData, psa->pvData, ulOldSize);
|
|
|
|
SAFEARRAY_Free(psa->pvData);
|
|
|
|
psa->pvData = pvNewData;
|
|
|
|
}
|
|
|
|
oldBounds->cElements = psabound->cElements;
|
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
SafeArrayUnlock(psa);
|
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2003-12-15 22:08:42 +01:00
|
|
|
* SafeArrayGetVartype (OLEAUT32.77)
|
|
|
|
*
|
|
|
|
* Get the type of the items in a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to get the type from
|
|
|
|
* pvt [O] Destination for the type
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. pvt contains the type of the items.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayGetVartype(SAFEARRAY* psa, VARTYPE* pvt)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p)\n", psa, pvt);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psa || !pvt)
|
|
|
|
return E_INVALIDARG;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psa->fFeatures & FADF_RECORD)
|
|
|
|
*pvt = VT_RECORD;
|
2008-07-25 00:32:35 +02:00
|
|
|
else if ((psa->fFeatures & (FADF_HAVEIID|FADF_DISPATCH)) == (FADF_HAVEIID|FADF_DISPATCH))
|
|
|
|
*pvt = VT_DISPATCH;
|
2003-12-15 22:08:42 +01:00
|
|
|
else if (psa->fFeatures & FADF_HAVEIID)
|
|
|
|
*pvt = VT_UNKNOWN;
|
|
|
|
else if (psa->fFeatures & FADF_HAVEVARTYPE)
|
|
|
|
{
|
|
|
|
VARTYPE vt = SAFEARRAY_GetHiddenDWORD(psa);
|
|
|
|
*pvt = vt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return E_INVALIDARG;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2003-12-15 22:08:42 +01:00
|
|
|
* SafeArraySetRecordInfo (OLEAUT32.@)
|
|
|
|
*
|
|
|
|
* Set the record info for a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to set the record info for
|
|
|
|
* pRinfo [I] Record info
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The record info is stored with the array.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArraySetRecordInfo(SAFEARRAY *psa, IRecordInfo *pRinfo)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
IRecordInfo** dest = (IRecordInfo**)psa;
|
2000-06-18 21:29:40 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p)\n", psa, pRinfo);
|
|
|
|
|
|
|
|
if (!psa || !(psa->fFeatures & FADF_RECORD))
|
|
|
|
return E_INVALIDARG;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (pRinfo)
|
|
|
|
IRecordInfo_AddRef(pRinfo);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (dest[-1])
|
|
|
|
IRecordInfo_Release(dest[-1]);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
dest[-1] = pRinfo;
|
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2003-12-15 22:08:42 +01:00
|
|
|
* SafeArrayGetRecordInfo (OLEAUT32.@)
|
|
|
|
*
|
|
|
|
* Get the record info from a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to get the record info from
|
|
|
|
* pRinfo [O] Destination for the record info
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. pRinfo contains the record info, or NULL if there was none.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayGetRecordInfo(SAFEARRAY *psa, IRecordInfo **pRinfo)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
IRecordInfo** src = (IRecordInfo**)psa;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p)\n", psa, pRinfo);
|
2003-06-13 18:35:07 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psa || !pRinfo || !(psa->fFeatures & FADF_RECORD))
|
|
|
|
return E_INVALIDARG;
|
2003-06-13 18:35:07 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
*pRinfo = src[-1];
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (*pRinfo)
|
|
|
|
IRecordInfo_AddRef(*pRinfo);
|
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2003-12-15 22:08:42 +01:00
|
|
|
* SafeArraySetIID (OLEAUT32.@)
|
|
|
|
*
|
|
|
|
* Set the IID for a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to set the IID from
|
|
|
|
* guid [I] IID
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. The IID is stored with the array
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArraySetIID(SAFEARRAY *psa, REFGUID guid)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
GUID* dest = (GUID*)psa;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%s)\n", psa, debugstr_guid(guid));
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psa || !guid || !(psa->fFeatures & FADF_HAVEIID))
|
|
|
|
return E_INVALIDARG;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
dest[-1] = *guid;
|
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2003-12-15 22:08:42 +01:00
|
|
|
* SafeArrayGetIID (OLEAUT32.@)
|
|
|
|
*
|
|
|
|
* Get the IID from a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Array to get the ID from
|
|
|
|
* pGuid [O] Destination for the IID
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. pRinfo contains the IID, or NULL if there was none.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
1999-01-24 19:52:55 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI SafeArrayGetIID(SAFEARRAY *psa, GUID *pGuid)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
GUID* src = (GUID*)psa;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p)\n", psa, pGuid);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psa || !pGuid || !(psa->fFeatures & FADF_HAVEIID))
|
|
|
|
return E_INVALIDARG;
|
2001-09-21 23:01:31 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
*pGuid = src[-1];
|
1999-01-24 19:52:55 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/************************************************************************
|
2003-12-15 22:08:42 +01:00
|
|
|
* VectorFromBstr (OLEAUT32.@)
|
|
|
|
*
|
|
|
|
* Create a SafeArray Vector from the bytes of a BSTR.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* bstr [I] String to get bytes from
|
|
|
|
* ppsa [O] Destination for the array
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. ppsa contains the strings bytes as a VT_UI1 array.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
2000-07-08 20:30:41 +02:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI VectorFromBstr(BSTR bstr, SAFEARRAY **ppsa)
|
2000-07-08 20:30:41 +02:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
SAFEARRAYBOUND sab;
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p,%p)\n", bstr, ppsa);
|
|
|
|
|
|
|
|
if (!ppsa)
|
|
|
|
return E_INVALIDARG;
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
sab.lLbound = 0;
|
|
|
|
sab.cElements = SysStringByteLen(bstr);
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
*ppsa = SAFEARRAY_Create(VT_UI1, 1, &sab, 0);
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (*ppsa)
|
2000-07-08 20:30:41 +02:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
memcpy((*ppsa)->pvData, bstr, sab.cElements);
|
2003-01-03 00:13:56 +01:00
|
|
|
return S_OK;
|
2000-07-08 20:30:41 +02:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2003-01-03 00:13:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
2003-12-15 22:08:42 +01:00
|
|
|
* BstrFromVector (OLEAUT32.@)
|
|
|
|
*
|
|
|
|
* Create a BSTR from a SafeArray.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* psa [I] Source array
|
|
|
|
* pbstr [O] Destination for output BSTR
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. pbstr contains the arrays data.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* psa must be a 1 dimensional array of a 1 byte type.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* See SafeArray.
|
2003-01-03 00:13:56 +01:00
|
|
|
*/
|
2003-12-15 22:08:42 +01:00
|
|
|
HRESULT WINAPI BstrFromVector(SAFEARRAY *psa, BSTR *pbstr)
|
|
|
|
{
|
|
|
|
TRACE("(%p,%p)\n", psa, pbstr);
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!pbstr)
|
2003-01-03 00:13:56 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
*pbstr = NULL;
|
2003-01-03 00:13:56 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psa || psa->cbElements != 1 || psa->cDims != 1)
|
2003-01-03 00:13:56 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
*pbstr = SysAllocStringByteLen(psa->pvData, psa->rgsabound[0].cElements);
|
|
|
|
if (!*pbstr)
|
|
|
|
return E_OUTOFMEMORY;
|
2003-01-03 00:13:56 +01:00
|
|
|
return S_OK;
|
2000-07-08 20:30:41 +02:00
|
|
|
}
|