Passing array of string to component 
Author Message
 Passing array of string to component

Hi.

I want to pass array of string to my component method.
The component method is implemented as follows :

STDMETHODIMP CCatalogService::PutDatabaseNames(VARIANT FAR*
pStringArray)
{
 // TODO: Add your implementation code here
 SAFEARRAY FAR* pSA = NULL;
 BSTR HUGEP* pBSTR;
 HRESULT hr;
 LONG cElements, lLBound, lUBound;

 if(V_VT(pStringArray) != (VT_ARRAY | VT_BSTR)) {
  return E_FAIL;
 }
 pSA = V_ARRAY(pStringArray);

 long dim = SafeArrayGetDim(pSA);
 if(dim != 1)
  return E_FAIL;

 hr = SafeArrayGetLBound(pSA, 1, &lLBound);
 if(FAILED(hr))
  return E_FAIL;
 hr = SafeArrayGetUBound(pSA, 1, &lUBound);
 if(FAILED(hr))
  return E_FAIL;

 hr = SafeArrayAccessData(pSA, (void HUGEP* FAR*)&pBSTR);
 if(FAILED(hr))
  return E_FAIL;

 cElements = lUBound - lLBound;

 ...

 hr = SafeArrayUnaccessData(pSA);
 if(FAILED(hr))
  return E_FAIL;

 return S_OK;

Quote:
}

In Visual Basic code, array of string is passed well.
Private Sub Command1_Click()
    Dim dbName As Variant
    ReDim dbName(3) As String

    For n = 0 To 3
        dbName(n) = "string" & Int(n)
    Next n

    oSearch.PutDatabaseNames(dbName)

End Sub

However, in my Javascript code I would pass an array of string as
follows
  var dbName = new Array(2);
  dbName[0] = "testdb";
  dbName[1] = "testdb2";
  oSearch.PutDatabaseNames(dbName);

But it is passed as IDispatch in the my component code i.e.
V_VT(pStringArray) is not (VT_ARRAY | VT_BSTR) but VT_DISPATCH.

How can I pass array of string to component in Javascript Code.

  skchoi.vcf
< 1K Download


Tue, 11 Feb 2003 09:20:35 GMT  
 Passing array of string to component

JavaScript never generates SAFEARRAY. You see, JavaScript arrays can have
properties assigned to them (length property is always assigned, but you can
add your own by simply writing

var dbName = new Array(2);
dbName[0] = "testdb";
dbName[1] = "testdb2";
dbName.xyz = "XYZ";

For this to work, JavaScript arrays are implemented as IDispatch
implementations. To get those properties, you use GetIDsOfNames("xyz",
&dispid) (pseudocode, of course) and then Invoke(dispid, DIPSATCH_PROPGET).
To get array element 0, you do exactly the same thing, except that the
property name is "0".
--
With best wishes,
    Igor Tandetnik


Quote:
> Hi.

> I want to pass array of string to my component method.
> The component method is implemented as follows :

> STDMETHODIMP CCatalogService::PutDatabaseNames(VARIANT FAR*
> pStringArray)
> {
>  // TODO: Add your implementation code here
>  SAFEARRAY FAR* pSA = NULL;
>  BSTR HUGEP* pBSTR;
>  HRESULT hr;
>  LONG cElements, lLBound, lUBound;

>  if(V_VT(pStringArray) != (VT_ARRAY | VT_BSTR)) {
>   return E_FAIL;
>  }
>  pSA = V_ARRAY(pStringArray);

>  long dim = SafeArrayGetDim(pSA);
>  if(dim != 1)
>   return E_FAIL;

>  hr = SafeArrayGetLBound(pSA, 1, &lLBound);
>  if(FAILED(hr))
>   return E_FAIL;
>  hr = SafeArrayGetUBound(pSA, 1, &lUBound);
>  if(FAILED(hr))
>   return E_FAIL;

>  hr = SafeArrayAccessData(pSA, (void HUGEP* FAR*)&pBSTR);
>  if(FAILED(hr))
>   return E_FAIL;

>  cElements = lUBound - lLBound;

>  ...

>  hr = SafeArrayUnaccessData(pSA);
>  if(FAILED(hr))
>   return E_FAIL;

>  return S_OK;
> }

> In Visual Basic code, array of string is passed well.
> Private Sub Command1_Click()
>     Dim dbName As Variant
>     ReDim dbName(3) As String

>     For n = 0 To 3
>         dbName(n) = "string" & Int(n)
>     Next n

>     oSearch.PutDatabaseNames(dbName)

> End Sub

> However, in my Javascript code I would pass an array of string as
> follows
>   var dbName = new Array(2);
>   dbName[0] = "testdb";
>   dbName[1] = "testdb2";
>   oSearch.PutDatabaseNames(dbName);

> But it is passed as IDispatch in the my component code i.e.
> V_VT(pStringArray) is not (VT_ARRAY | VT_BSTR) but VT_DISPATCH.

> How can I pass array of string to component in Javascript Code.



Tue, 11 Feb 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How To pass 2D String array to VB from VC++ Using Safe array

2. Passing arrays to a COM component

3. Passing in/out,retval arrays from C# code to COM Component developed with C++

4. Passing an array of VARIANTs to a COM component

5. passing strings from ATL component to VB app

6. Passing a string in a C# COM component

7. String Array to VB Component.

8. Passing String arrays by reference?

9. Passing array of strings to a function?

10. How to pass FileNames of OpenFileDialog as String Array

11. Passing an array of char strings by descriptor

12. passing string array

 

 
Powered by phpBB® Forum Software