Connecting Tech Pros Worldwide Forums | Help | Site Map

returning arrays from COM to JScript

Newbie
 
Join Date: Sep 2007
Location: 中国民主社会主义党Democratic Socialist Party C
Posts: 2
#1: Sep 25 '07
On Apr 28 2001, 6:06 am, "Michael Harris" <mik...@mvps.org> wrote:

> "...So there is no way to transparentlyreturnanarrayinJScript?..."

> To be "JScript-friendly", you have toreturn*everything" via a >functionreturnvalue. And as I
> said before,JScriptcan handle a SAFEARRAY by converting it with VBArray() >since aJScriptarray
> isn't really anarraybut rather a special (IDispatch[Ex] based)JScriptobject with >numeric
> properties.

JScript takes array[0] as array.0

Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,375
#2: Sep 25 '07

re: returning arrays from COM to JScript


What's the question?
Newbie
 
Join Date: Sep 2007
Location: 中国民主社会主义党Democratic Socialist Party C
Posts: 2
#3: Sep 26 '07

re: returning arrays from COM to JScript


Quote:
What's the question?
http://groups.google.com/group/microsoft.public.scripting.jscript/browse_thread/thread/0e10ec0571c9ca48/2d160e9d46d49c3e


JScript takes array[0][1] as array.0.1


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. STDMETHODIMP CUfmArray::XLocalClass::GetDispID( 
  4.       BSTR bstrName, DWORD grfdex, DISPID *pid)
  5. {
  6.     METHOD_PROLOGUE(CUfmArray, LocalClass)
  7.  
  8.     CString strValue;
  9.     if(pThis->m_psaAry.Lookup(CString(bstrName),strValue))
  10.     {
  11.         *pid =pThis->m_pidAry->GetCount()+0x1000;
  12.         pThis->m_pidAry->AddTail(strValue);
  13.  
  14.         return S_OK;
  15.     }
  16.     return pThis->m_JuggleAry->GetDispID( bstrName,  grfdex,  pid);
  17. }
  18.  
  19. STDMETHODIMP CUfmArray::XLocalClass::InvokeEx( 
  20.      DISPID id, LCID lcid, WORD wFlags,
  21.      DISPPARAMS *pdp,  VARIANT *pvarRes, EXCEPINFO *pei,
  22.      IServiceProvider *pspCaller)
  23. {
  24.     METHOD_PROLOGUE(CUfmArray, LocalClass)
  25.  
  26.     CString strValue;
  27.     if(strValue = pThis->m_pidAry->GetAt(pThis->m_pidAry->FindIndex(id-0x1000)))
  28.     {
  29.             // Validate that they passed in a valid variant for results
  30.             // and have no parameters assigned to the "Get"
  31.             if( pvarRes != NULL &&
  32.                 (pdp == NULL || pdp->cArgs == 0) )
  33.             {
  34.                 // Do the "Get" with the specified ID
  35.                 VariantClear(pvarRes);
  36.                 pvarRes->vt =VT_BSTR;
  37.                 pvarRes->bstrVal = strValue.AllocSysString();
  38.             }
  39.             else
  40.             {
  41.                 // They passed in bogus stuff
  42.                 return E_INVALIDARG;
  43.             }
  44.         return S_OK;
  45.     }
  46.  
  47.  
  48.     HRESULT hr = pThis->m_JuggleAry->InvokeEx(  id,  lcid,  wFlags,
  49.       pdp,   pvarRes,  pei,
  50.       pspCaller);
  51.  
  52.     if(hr ==E_POINTER)
  53.     {
  54.         IUfmArray* pSry =(IUfmArray*)pThis->GetInterface(&IID_IUfmArray);
  55.  
  56.  
  57.                 UINT nErrArg = 0;
  58.  
  59.                 hr =pSry->Invoke(  id, IID_NULL, lcid,  wFlags,
  60.       pdp,   pvarRes,  pei,
  61.       &nErrArg);
  62.     }
  63.     return hr;
  64. }
  65.  
  66.  
Reply


Similar C / C++ bytes