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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
/* Allocate memory */
|
|
|
|
static inline LPVOID SAFEARRAY_Malloc(ULONG ulSize)
|
|
|
|
{
|
|
|
|
/* FIXME: Memory should be allocated and freed using a per-thread IMalloc
|
|
|
|
* instance returned from CoGetMalloc().
|
|
|
|
*/
|
|
|
|
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free memory */
|
|
|
|
static inline BOOL SAFEARRAY_Free(LPVOID lpData)
|
|
|
|
{
|
|
|
|
return HeapFree(GetProcessHeap(), 0, lpData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
/* Get the 0 based index of an index into a dimension */
|
|
|
|
static inline ULONG SAFEARRAY_GetDimensionIndex(SAFEARRAYBOUND *psab, ULONG ulIndex)
|
|
|
|
{
|
|
|
|
return ulIndex - psab->lLbound;
|
|
|
|
}
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/* Get the size of a dimension in cells */
|
|
|
|
static inline ULONG SAFEARRAY_GetDimensionCells(SAFEARRAY *psa, ULONG ulDim)
|
|
|
|
{
|
|
|
|
ULONG size = psa->rgsabound[0].cElements;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
while (ulDim)
|
|
|
|
{
|
|
|
|
size *= psa->rgsabound[ulDim].cElements;
|
|
|
|
ulDim--;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a descriptor for an array */
|
|
|
|
static HRESULT SAFEARRAY_AllocDescriptor(ULONG ulSize, SAFEARRAY **ppsaOut)
|
|
|
|
{
|
|
|
|
*ppsaOut = (SAFEARRAY*)((char*)SAFEARRAY_Malloc(ulSize + SAFEARRAY_HIDDEN_SIZE) + SAFEARRAY_HIDDEN_SIZE);
|
|
|
|
|
|
|
|
if (!*ppsaOut)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
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 */
|
|
|
|
static SAFEARRAY* SAFEARRAY_Create(VARTYPE vt, UINT cDims, SAFEARRAYBOUND *rgsabound, ULONG ulSize)
|
|
|
|
{
|
|
|
|
SAFEARRAY *psa = NULL;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(psa->rgsabound, rgsabound, cDims * sizeof(SAFEARRAYBOUND));
|
|
|
|
|
|
|
|
if (ulSize)
|
|
|
|
psa->cbElements = ulSize;
|
|
|
|
|
|
|
|
if (FAILED(SafeArrayAllocData(psa)))
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
FIXME("unexpted ulcellcount %ld, start %ld\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))
|
|
|
|
{
|
|
|
|
LPUNKNOWN *lpUnknown = (LPUNKNOWN *)psa->pvData + ulStartCell * psa->cbElements;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
|
|
|
if (*lpUnknown)
|
|
|
|
IUnknown_Release(*lpUnknown);
|
|
|
|
lpUnknown++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & (FADF_RECORD))
|
|
|
|
{
|
|
|
|
IRecordInfo *lpRecInfo;
|
|
|
|
|
|
|
|
if (SUCCEEDED(SafeArrayGetRecordInfo(psa, &lpRecInfo)))
|
|
|
|
{
|
|
|
|
PBYTE pRecordData = (PBYTE)psa->pvData;
|
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
|
|
|
IRecordInfo_RecordClear(lpRecInfo, pRecordData);
|
|
|
|
pRecordData += psa->cbElements;
|
|
|
|
}
|
|
|
|
IRecordInfo_Release(lpRecInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_BSTR)
|
|
|
|
{
|
|
|
|
BSTR* lpBstr = (BSTR*)psa->pvData + ulStartCell * psa->cbElements;
|
|
|
|
|
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
|
|
|
if (*lpBstr)
|
|
|
|
SysFreeString(*lpBstr);
|
|
|
|
lpBstr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_VARIANT)
|
|
|
|
{
|
|
|
|
VARIANT* lpVariant = (VARIANT*)psa->pvData + ulStartCell * psa->cbElements;
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
/* Copy data items from one array to another */
|
|
|
|
static HRESULT SAFEARRAY_CopyData(SAFEARRAY *psa, SAFEARRAY *dest)
|
1999-01-24 19:52:55 +01:00
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!psa->pvData || !dest->pvData || psa->fFeatures & FADF_DATADELETED)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ULONG ulCellCount = SAFEARRAY_GetCellCount(psa);
|
1999-03-10 14:25:27 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
dest->fFeatures = (dest->fFeatures & FADF_CREATEVECTOR) |
|
|
|
|
(psa->fFeatures & ~(FADF_CREATEVECTOR|FADF_DATADELETED));
|
|
|
|
|
|
|
|
if (psa->fFeatures & FADF_VARIANT)
|
|
|
|
{
|
|
|
|
VARIANT* lpVariant = (VARIANT*)psa->pvData;
|
|
|
|
VARIANT* lpDest = (VARIANT*)dest->pvData;
|
|
|
|
|
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
2004-09-20 21:11:48 +02:00
|
|
|
HRESULT hRet;
|
|
|
|
|
|
|
|
hRet = VariantCopy(lpDest, lpVariant);
|
|
|
|
if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%lx\n", hRet);
|
2003-12-15 22:08:42 +01:00
|
|
|
lpVariant++;
|
|
|
|
lpDest++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_BSTR)
|
|
|
|
{
|
|
|
|
BSTR* lpBstr = (BSTR*)psa->pvData;
|
|
|
|
BSTR* lpDest = (BSTR*)dest->pvData;
|
|
|
|
|
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
|
|
|
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 (!*lpDest)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*lpDest = NULL;
|
|
|
|
lpBstr++;
|
|
|
|
lpDest++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Copy the data over */
|
|
|
|
memcpy(dest->pvData, psa->pvData, ulCellCount * psa->cbElements);
|
|
|
|
|
|
|
|
if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
|
|
|
|
{
|
|
|
|
LPUNKNOWN *lpUnknown = (LPUNKNOWN *)dest->pvData;
|
|
|
|
|
|
|
|
while(ulCellCount--)
|
|
|
|
{
|
|
|
|
if (*lpUnknown)
|
|
|
|
IUnknown_AddRef(*lpUnknown);
|
|
|
|
lpUnknown++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (psa->fFeatures & FADF_RECORD)
|
|
|
|
{
|
|
|
|
IRecordInfo* pRecInfo = NULL;
|
|
|
|
|
|
|
|
SafeArrayGetRecordInfo(psa, &pRecInfo);
|
|
|
|
SafeArraySetRecordInfo(dest, pRecInfo);
|
|
|
|
|
|
|
|
if (pRecInfo)
|
|
|
|
{
|
|
|
|
/* Release because Get() adds a reference */
|
|
|
|
IRecordInfo_Release(pRecInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_HAVEIID)
|
|
|
|
{
|
|
|
|
GUID guid;
|
|
|
|
SafeArrayGetIID(psa, &guid);
|
|
|
|
SafeArraySetIID(dest, &guid);
|
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_HAVEVARTYPE)
|
|
|
|
{
|
|
|
|
SAFEARRAY_SetHiddenDWORD(dest, SAFEARRAY_GetHiddenDWORD(psa));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
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;
|
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
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (FAILED(SAFEARRAY_AllocDescriptor(allocSize, ppsaOut)))
|
|
|
|
return E_UNEXPECTED;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
(*ppsaOut)->cDims = cDims;
|
|
|
|
|
|
|
|
TRACE("(%d): %lu bytes allocated for descriptor.\n", cDims, allocSize);
|
|
|
|
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
|
|
|
|
* - This function does not chack that vt is an allowed VARTYPE.
|
|
|
|
* - 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;
|
|
|
|
HRESULT hRet = E_UNEXPECTED;
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
hRet = E_OUTOFMEMORY;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-30 20:06:41 +01:00
|
|
|
if (psa->cbElements)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
|
|
|
psa->pvData = SAFEARRAY_Malloc(ulSize * psa->cbElements);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psa->pvData)
|
|
|
|
{
|
|
|
|
hRet = S_OK;
|
|
|
|
TRACE("%lu bytes allocated for data at %p (%lu objects).\n",
|
|
|
|
ulSize * psa->cbElements, psa->pvData, ulSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
IRecordInfo* iRecInfo = (IRecordInfo*)pvExtra;
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
TRACE("(%d->%s,%ld,%ld\n", vt, debugstr_vt(vt), lLbound, cElements);
|
|
|
|
|
|
|
|
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;
|
|
|
|
IRecordInfo* iRecInfo = (IRecordInfo*)pvExtra;
|
|
|
|
SAFEARRAY* psa;
|
|
|
|
|
|
|
|
TRACE("(%d->%s,%ld,%ld,%p\n", vt, debugstr_vt(vt), lLbound, cElements, pvExtra);
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!SAFEARRAY_Free(lpv))
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
2005-08-08 20:38:29 +02:00
|
|
|
if ((LONG)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
|
|
|
if (!pvData)
|
|
|
|
{
|
|
|
|
ERR("Invalid pvData would crash under Win32!\n");
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2002-06-01 01:06:46 +02: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)
|
|
|
|
{
|
|
|
|
VARIANT* lpVariant = (VARIANT*)pvData;
|
|
|
|
VARIANT* lpDest = (VARIANT*)lpvDest;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2004-09-20 21:11:48 +02:00
|
|
|
hRet = VariantClear(lpDest);
|
|
|
|
if (FAILED(hRet)) FIXME("VariantClear failed with 0x%lx\n", hRet);
|
|
|
|
hRet = VariantCopy(lpDest, lpVariant);
|
|
|
|
if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%lx\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;
|
2003-12-15 22:08:42 +01:00
|
|
|
BSTR* lpDest = (BSTR*)lpvDest;
|
|
|
|
|
|
|
|
if (*lpDest)
|
|
|
|
SysFreeString(*lpDest);
|
|
|
|
|
2003-12-30 20:06:41 +01:00
|
|
|
if (lpBstr)
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
2004-01-09 01:58:01 +01:00
|
|
|
*lpDest = SysAllocStringByteLen((char*)lpBstr, SysStringByteLen(lpBstr));
|
2003-12-15 22:08:42 +01:00
|
|
|
if (!*lpDest)
|
|
|
|
hRet = E_OUTOFMEMORY;
|
2001-09-21 23:01:31 +02:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
else
|
|
|
|
*lpDest = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
|
|
|
|
{
|
2003-12-30 20:06:41 +01:00
|
|
|
LPUNKNOWN lpUnknown = (LPUNKNOWN)pvData;
|
2003-12-15 22:08:42 +01:00
|
|
|
LPUNKNOWN *lpDest = (LPUNKNOWN *)lpvDest;
|
|
|
|
|
2003-12-30 20:06:41 +01:00
|
|
|
if (lpUnknown)
|
|
|
|
IUnknown_AddRef(lpUnknown);
|
2003-12-15 22:08:42 +01:00
|
|
|
if (*lpDest)
|
|
|
|
IUnknown_Release(*lpDest);
|
2003-12-30 20:06:41 +01:00
|
|
|
*lpDest = lpUnknown;
|
|
|
|
} else {
|
|
|
|
/* Copy the data over */
|
|
|
|
memcpy(lpvDest, pvData, psa->cbElements);
|
|
|
|
}
|
2001-09-21 23:01:31 +02:00
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
VARIANT* lpVariant = (VARIANT*)lpvSrc;
|
|
|
|
VARIANT* lpDest = (VARIANT*)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);
|
|
|
|
if (FAILED(hRet)) FIXME("VariantCopy failed with 0x%lx\n", hRet);
|
2003-12-15 22:08:42 +01:00
|
|
|
}
|
|
|
|
else if (psa->fFeatures & FADF_BSTR)
|
|
|
|
{
|
|
|
|
BSTR* lpBstr = (BSTR*)lpvSrc;
|
|
|
|
BSTR* lpDest = (BSTR*)pvData;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (psa->fFeatures & (FADF_UNKNOWN|FADF_DISPATCH))
|
|
|
|
{
|
|
|
|
LPUNKNOWN *lpUnknown = (LPUNKNOWN *)lpvSrc;
|
|
|
|
|
|
|
|
if (*lpUnknown)
|
|
|
|
IUnknown_AddRef(*lpUnknown);
|
|
|
|
}
|
|
|
|
/* 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;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
*plUbound = psa->rgsabound[nDim - 1].lLbound +
|
|
|
|
psa->rgsabound[nDim - 1].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
|
|
|
|
* nDim [I] The dimension number to get the lowe bound of
|
|
|
|
* 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
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
*plLbound = psa->rgsabound[nDim - 1].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
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p) returning %ld\n", psa, psa ? psa->cDims : 0ul);
|
|
|
|
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
|
|
|
{
|
2003-12-15 22:08:42 +01:00
|
|
|
TRACE("(%p) returning %ld\n", psa, psa ? psa->cbElements : 0ul);
|
|
|
|
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
|
|
|
{
|
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;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (SUCCEEDED(SafeArrayLock(psa)))
|
|
|
|
{
|
|
|
|
*ppvData = psa->pvData;
|
|
|
|
return S_OK;
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
*ppvData = NULL;
|
|
|
|
return E_UNEXPECTED;
|
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;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
psab = psa->rgsabound;
|
|
|
|
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
|
|
|
|
2003-12-15 22:08:42 +01: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
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
cell += (c1 - psa->rgsabound[0].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)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2004-10-19 23:08:02 +02:00
|
|
|
/* If static, keep pvData and don't free */
|
|
|
|
if (psa->pvData && !(psa->fFeatures & FADF_STATIC))
|
2003-12-15 22:08:42 +01:00
|
|
|
{
|
|
|
|
/* Delete the actual item data */
|
|
|
|
if (FAILED(SAFEARRAY_DestroyData(psa, 0)))
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
/* If this is not a vector, free the data memory block */
|
|
|
|
if (!(psa->fFeatures & FADF_CREATEVECTOR))
|
|
|
|
{
|
|
|
|
if (!SAFEARRAY_Free(psa->pvData))
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
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;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (SUCCEEDED(SAFEARRAY_DestroyData(psaTarget, 0)) &&
|
|
|
|
SUCCEEDED(SAFEARRAY_CopyData(psaSource, psaTarget)))
|
|
|
|
return S_OK;
|
|
|
|
return E_UNEXPECTED;
|
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
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (psa->fFeatures & (FADF_RECORD|FADF_HAVEIID|FADF_HAVEVARTYPE))
|
|
|
|
{
|
|
|
|
VARTYPE vt;
|
|
|
|
if (FAILED(SafeArrayGetVartype(psa, &vt)))
|
|
|
|
hRet = E_UNEXPECTED;
|
|
|
|
else
|
|
|
|
hRet = SafeArrayAllocDescriptorEx(vt, psa->cDims, ppsaOut);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hRet = SafeArrayAllocDescriptor(psa->cDims, ppsaOut);
|
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
{
|
|
|
|
(*ppsaOut)->fFeatures = psa->fFeatures & ~FADF_CREATEVECTOR;
|
|
|
|
(*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);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if ((*ppsaOut)->pvData)
|
|
|
|
{
|
|
|
|
hRet = SAFEARRAY_CopyData(psa, *ppsaOut);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
return hRet;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
SAFEARRAY_Free((*ppsaOut)->pvData);
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
SafeArrayDestroyDescriptor(*ppsaOut);
|
1999-01-24 19:52:55 +01:00
|
|
|
}
|
2003-12-15 22:08:42 +01:00
|
|
|
*ppsaOut = NULL;
|
|
|
|
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;
|
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;
|
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
if (FAILED(SafeArrayLock(psa)))
|
|
|
|
return E_UNEXPECTED;
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
oldBounds = &psa->rgsabound[psa->cDims - 1];
|
|
|
|
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. */
|
|
|
|
ULONG ulStartCell = psa->cDims == 1 ? 0 : SAFEARRAY_GetDimensionCells(psa, psa->cDims - 1);
|
1999-01-24 19:52:55 +01:00
|
|
|
|
2003-12-15 22:08:42 +01:00
|
|
|
ulStartCell += psabound->cElements;
|
|
|
|
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);
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
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;
|
|
|
|
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
|
|
|
}
|