Someone asked SAFEARRAY the day before yesterday. I was interested in how to get the array returned by the COM component in vb script. I tried it.
The IDE uses VC7.1.
At the beginning, it's almost the same. Create a project, create a COM object, and create a method:
Interface Definition:
[Id (2), helpstring ("method GetArray")] HRESULT GetArray1 ([out, retval] VARIANT * v );
Method implementation:
STDMETHODIMP CATL3: GetArray1 (VARIANT * pvaVariant)
{
Std: vector <float> vct;
Vct. push_back (11.4 );
Vct. push_back (12.4 );
Vct. push_back (14.4 );
CComSafeArray <VARIANT> saMatrix;
For (int I = 0; I <vct. size (); ++ I)
{
SaMatrix. Add (CComVariant (vct [I]);
}
VariantInit (pvaVariant );
CComVariant var (saMatrix );
Var. Detach (pvaVariant );
Return S_ OK;
}
Note that the returned array parameters must be obtained in VBS or other script environments. The type in the array is VARIANT.
VBS test script
Dim v4
Cnxn4.Add 1, 2
V4 = Cnxn4.GetArray1 ()
Dim x
For x = Lbound (v4) To Ubound (v4)
MsgBox v4 (x)
Next