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:57 +0100,    group: microsoft.public.platformsdk.com_ole        back       


com returning 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:57 +0100   author:   micha

Re: com returning arrays   
sorry for posting twice
date: Tue, 29 Nov 2005 10:26:23 +0100   author:   micha

Re: com returning arrays   
"micha"  wrote in message
news:op.s0zv5vd6vqen59@miwexp.berlin.promess-gmbh.de
> from within a com-server i want to fill an array (of int or long) and
> return that to a vbscript-client.

Be aware that the only kind of array VBScript supports is a safearray of 
variants.

> 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.

Make it

HRESULT Count([in] VARIANT CharacteristicFlags,
    [out, retval] SAFEARRAY(VARIANT)* pIndices);

On the C++ side this would translate to

STDMETHODIMP Count(VARIANT CharacteristicFlags,
    SAFEARRAY** 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?

Once you change the signature as shown above, this should become 
obvious.
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Tue, 29 Nov 2005 07:57:37 -0500   author:   Igor Tandetnik

Re: com returning arrays   
> Be aware that the only kind of array VBScript supports is a safearray of
> variants.
>
by now i do it like that:
STDMETHODIMP CICharacteristics::Count(VARIANT CharacteristicFlags, VARIANT  
*pIndices, VARIANT *pCount)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())

//miwe051128 methode aus managers rufen
CDWordArray indices;
const CCharacteristic::ITERATION_FLAGS flags =
(CCharacteristic::ITERATION_FLAGS)RVariant(CharacteristicFlags).Int();
const int intRetVal = Characteristics().Count(flags, indices);

//miwe051128 Rckgabewert (einfacher int) in com-variant packen
VariantInit( pCount );
VariantCopy( pCount, &CComVariant(intRetVal) );

//miwe051128 ermittelte indizes als safearray[variant] zurckgeben
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 );
pIndices->vt = VT_ARRAY | VT_VARIANT;
pIndices->parray = pParamArray;

return S_OK;
}

....and it seems to work for me. on the server a return an variant,  
containing a safearray which consists of elements of variant.
in vbscript i get my array and can work with it.
is this just "accidentelly correct"?

-- 
micha
date: Tue, 29 Nov 2005 14:19:26 +0100   author:   micha

Re: com returning arrays   
micha  wrote:
>> Be aware that the only kind of array VBScript supports is a
>> safearray of variants.
>>
> by now i do it like that:
> STDMETHODIMP CICharacteristics::Count(VARIANT CharacteristicFlags,
> VARIANT *pIndices, VARIANT *pCount)
> {
[snip]
>
> VariantInit( pIndices );
> pIndices->vt = VT_ARRAY | VT_VARIANT;
> pIndices->parray = pParamArray;
>
> return S_OK;
> }
>
> ...and it seems to work for me.

That's OK. It roughly corresponds to

HRESULT Count([in] VARIANT CharacteristicFlags,
    [out, retval] VARIANT* pIndices);

where pIndices variant is set to contain a safearray. You don't need 
pCount parameter at all - safearray is self-describing, the script can 
and does retrieve the size from safearray itself. Just drop pCount 
parameter.
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Tue, 29 Nov 2005 09:48:18 -0500   author:   Igor Tandetnik

Google
 
Web ureader.com


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