com retuning arrays
hallo
from within a com-server i want to fill an array (of int or long) and
return that to a vbscript-client.
i declared the com-method as follows:
[id(11), helpstring("Methode Count")] HRESULT Count([in] VARIANT
CharacteristicFlags, [out] VARIANT*
pIndices, [out, retval] VARIANT* pCount);
the array to return is in pIndices.
in the implementation of the method i built an SAFEARRAY* (containing
elements of VARIANT*) wich is the one i want to return in pIndices.
my problem is how to put this SAFEARRAY* into the VARIANT* pIndices to
return it to vbscipt?
i tried declaring the method with [out] SAFEARRAY** instead of VARIANT*
but that gives me a warning this is not automation-compatible and the
vbscript-call gives me an systax error.
anyone knows what to do or where i can find examples?
my implemented method by now:
STDMETHODIMP CICharacteristics::Count(VARIANT CharacteristicFlags, VARIANT
*pIndices, VARIANT *pCount)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
//miwe051128 call internal method to get array and return-value
CDWordArray indices;
const CCharacteristic::ITERATION_FLAGS flags =
(CCharacteristic::ITERATION_FLAGS)RVariant(CharacteristicFlags).Int();
const int intRetVal = Characteristics().Count(flags, indices);
//miwe051128 put return-value of method (int) into variant
VariantInit( pCount );
VariantCopy( pCount, &CComVariant(intRetVal) );
//miwe051128 put calculated indices into SAFEARRAY
const int elementCount = indices.GetSize();
VARIANT* rgVarParam = new VARIANT[elementCount];
SAFEARRAY* pParamArray;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = elementCount;
pParamArray = ::SafeArrayCreate(VT_VARIANT, 1, rgsabound);
if (NULL == pParamArray)
{
return E_OUTOFMEMORY;
}
HRESULT hResult;
for (long intIndexC=0; intIndexC<elementCount; intIndexC++){
::VariantInit(&rgVarParam[intIndexC]);
VariantCopy(&rgVarParam[intIndexC],
&CComVariant((int)indices.GetAt(intIndexC)));
hResult = ::SafeArrayPutElement(pParamArray, &intIndexC,
(void*)&rgVarParam[intIndexC]);
if (hResult != S_OK){
return hResult;
}
}
delete[] rgVarParam;
VariantInit( pIndices );
//TODO PUT SAFEARRAY (pParamArray) INTO OUT-VARIANT (pIndices, )
return S_OK;
}
greetings
--
micha
date: Tue, 29 Nov 2005 10:18:41 +0100
author: micha