• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 930
  • Last Modified:

How to get a method "out" parameter values from Vbscript

I have a .NET class that I register (with regasm) as a
COM object. It has a method that returns to caller an array of ints. I
create that object from Vbscript and try to get the returned array,
but get a runtime error.

The .NET class (simplified):

public class myclass {
   public myclass{
     ...
   }
   public int link(string ip){
     // no problem calling this method
     ...
     return 1;
   }
   public int getcounter(int param1, out ulong[] myarray){
     // can't call this method
     myarray = new ulong[2];
     myarray[0] = 0;
     myarray[1] = 1;
     return 1;
   }
}

The class is registred with regasm and called from vbscript as follows

'this is test.vbs
dim arr
set myobj = CreateObject("myclass.myclass")
ret = myobj.link("192.168.100.101")
ret = myobj.getcounter(1, arr)

Creation of the object and the call to "link" method works fine. The
call to getcounter throws at vbscript exception 800A0005 "Invalid
procedure call or argument: 'getcounter'"

I guess this has to do with the "out" parameter, but I don't know how
to make this work.

Thanks,
careta
0
careta
Asked:
careta
  • 3
  • 2
  • 2
1 Solution
 
smeggheadCommented:
I know VB never had a concept of 'out' variables, so I very much doubt that VBScript would have.

I would just change it to 'ref'

or alternatively (and probably preferably), just call a separate function to return the array

Smg.
0
 
caretaAuthor Commented:
First, I never had a problem to call an interface's method with "out" parameters from VB.
Second, changing to "ref" doesn't work either.
Third, it looks as a serious limitation to be able to return a single value per method.

careta
0
 
smeggheadCommented:
what happens if you change ulong to int ?? just out of interest. It may be this that's causing the problem.

Smg.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
caretaAuthor Commented:
the same...
0
 
testnCommented:
int is 32-bit and long is 64-bit in C# while
Integer is 16-bit and Long is 32-bit in VB. Therefore, you should use int instead to make VB able to refer to your object.
0
 
caretaAuthor Commented:
I tried both: long and int, with same results.
I did some browsing in the interop newsgroup and it looks as there is some limitation with "out" or "ref" parameters from a .NET COM object and VB flavors. Is that possible? it's hard to believe, but that's what I see.
0
 
testnCommented:
Oh, I just noticed that you're using VBScript not VB6. In that case, I think there is no way that you can pass object as an array since VBscript is loosely typed language.

You might try to return your array as an object. Let's try. Might work
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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