Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Tue, 29 Nov 2005 10:18:41 +0100,    group: microsoft.public.platformsdk.com_ole        back       


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

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us