Link to home
Start Free TrialLog in
Avatar of AntoFreeman
AntoFreeman

asked on

Passing Array From VBScript To Com Object

hi,

I'm trying to pass a 2d array from vbscript to a com object.  By have been having problems.

First in my idl I have:

interface ICxSafeArrayTest : IDispatch
      {
            [id(1), helpstring("method PassArray")] HRESULT PassArray([in]SAFEARRAY(VARIANT) pArray);
      };  

and in my script I have :
Dim var
Dim safeArray()
ReDim safeArray(2,2,)

var = 10
safeArray(0,0) = var
 ...
 ...
comObject.PassArray safeArray

I keep getting a type mismatch and when I created a test app with vb I got the error: "Function or interface marked as restricted, or the function uses an Automation type not supported in VB".

I have also tried declaring the array type as VARIANT

interface ICxSafeArrayTest : IDispatch
      {
            [id(1), helpstring("method PassArray")] HRESULT PassArray([in]VARIANT vArray);
      };  

this works through visual basic but not through the scripts.  When I pass like this through the script the vt of the variant is (VT_VARIANT|VT_BYREF) but the parray and pparray sections of the VARIANT have a valid pointer but garbage values.  Any idea's!!!????

Cheers
ASKER CERTIFIED SOLUTION
Avatar of choo_chu
choo_chu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of choo_chu
choo_chu

Hi again...

Oops...I reread your post and saw that you are having issues in VB, so I made a small program to test the COM code.  The code I posted above worked fine from VB.


choo_chu
Try this.

Dim var
Dim safeArray()
ReDim safeArray(2,2,)

var = 10
safeArray(0,0) = var
 ...
 ...
Dim var2
var2 = safeArray
comObject.PassArray var2 or comObject.PassArray ((var2))

I have run across a few cases when passing an array to a safearray you had to pass it through a variant type from a variant array type and at times pass it through with double parantheses
Avatar of AntoFreeman

ASKER

Thanks very much but thought I had done this already and it didnt work, but obviously not because it works now :)