
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.