|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
Re: Passing variant arrays from asp to atl component doesn't work
From: Katiyar, Subodh (Path) (skatiyar
AFSINDIA.COM)
Date: Tue Feb 17 2004 - 23:42:21 CST
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
kim
i can't help laughing at my stupid pArray->cDims=1 mistake
the sample code works fine when it is called from vb client
when i call it from asp client with an array of (2,4) with following values
vin(0,0)="a"
vin(0,1)="b"
vin(0,2)="c"
.....
and so on i fill till h
when i try to call this asp page
i get -> a e b f c g Vame from dbl dim
now what could be misbehaving in here?and one more thing if i pass it a single dim array from asp it prints fine.
regards
-----Original Message-----
From: Kim Gräsman [mailto:kim.grasman
LABS2.COM]
Sent: Wednesday, February 18, 2004 12:34 Subah
To: DCOM
DISCUSS.MICROSOFT.COM
Subject: Re: Passing variant arrays from asp to atl component doesn't
work
Hi Subodh,
> if (!(vin->vt & VT_ARRAY) || !(vin->vt & VT_BSTR))
> return 1 ;
This implies that you're looking for a SAFEARRAY of BSTR... VBScript only
handles SAFEARRAY of VARIANT, so I'm surprised that it works at all.
> if (pArray->cDims=1)
> //problem here cDims is always 1 either i pass single dim or dbl dim
No surprise - you're assigning one to pArray->cDims.
All in all, here are a couple of tips:
- Be as explicit with types as you can, i.e. prefer BSTR to VARIANT (what is
spmname? verr?)
- Always dereference incoming VARIANTs, either with VariantCopyInd
(expensive), or some manual inspection (cheap, but cumbersome)
- Avoid [out] only with scripting languages. VBScript can't figure out how
to deallocate complex types (BSTR, objects, arrays, etc) with [out], only
with [out, retval].
See below for a working version.
Hope that helps,
Kim
// ---
STDMETHODIMP CInvoke::Go(VARIANT *spmname, VARIANT *vin, VARIANT *vout,
VARIANT *verr)
{
HRESULT hr;
CComBSTR newBstr;
// Dereference variant
CComVariant vaInArray;
hr = VariantCopyInd(&vaInArray, vin);
if(FAILED(hr)) return hr;
// Validate
if(vaInArray.vt != (VT_ARRAY | VT_VARIANT))
{
return E_INVALIDARG;
}
// Access raw variant data
VARIANT* bvararrayddim = NULL;
SAFEARRAY* psa = vaInArray.parray;
::SafeArrayAccessData (psa, (void**)&bvararrayddim);
// Traverse variant buffer, and build BSTR
long c = 0;
for(int j = 0; j < psa->cDims; j++)
{
for(unsigned int i = 0; i < psa->rgsabound[j].cElements;
i++, c++)
{
if(bvararrayddim[c].vt == VT_BSTR)
{
newBstr += bvararrayddim[c].bstrVal;
}
}
}
// Append some value and return
newBstr += "Vame from dbl dim";
verr->vt = VT_BSTR;
verr->bstrVal = newBstr.Detach();
return S_OK;
}
----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.html
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:DCOM-signoff-request
DISCUSS.MICROSOFT.COM
DISCLAIMER:
The information contained in this Message is confidential and intended only for the use of the individual or entity identified. If the reader of this message is not the intended recipient, any dissemination, distribution or copying of the information contained in this message is strictly prohibited. If you received this message in error, please notify the sender immediately.
----------------------------------------------------------------
Users Guide http://discuss.microsoft.com/archives/mailfaq.html
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:DCOM-signoff-request
DISCUSS.MICROSOFT.COM
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]