[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2234
  • Last Modified:

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
0
AntoFreeman
Asked:
AntoFreeman
  • 2
1 Solution
 
choo_chuCommented:
Hi AntoFreeman,

I haven't tried my results with VB, just with the VBScript, since that is what you are having problems with.  I used a VARIANT* as the parameter thru which the 2d array is passed.  I also tested with a regular array and found no issues.  

My IDL looks like this:

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

My c++ method is like this:

STDMETHODIMP PassArrayClass::PassArray( /*[in]*/VARIANT* pArray)
{
      // TODO: Add your implementation code here
      return S_OK;
}    

and I tested with the following ASP/VBScript:

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

      safeArray(0, 0) = "Hello!"

      Response.Write "BEFORE: " & safeArray(0, 0)

      Set obj = Server.CreateObject( "EE.PassArrayClass" )

      obj.PassArray( safeArray )

      Response.Write "AFTER: " & safeArray(0, 0)

      Set obj = Nothing
%>

I hope this helps.

Good luck,
choo_chu
0
 
choo_chuCommented:
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
0
 
Corey ScheichDeveloperCommented:
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
0
 
AntoFreemanAuthor Commented:
Thanks very much but thought I had done this already and it didnt work, but obviously not because it works now :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now