Re: OLEAutomation Interop with object []

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Robert Jordan (robertj_at_gmx.net)
Date: 08/27/04


Date: Fri, 27 Aug 2004 10:13:23 +0200

Hi Phil,

> There doesn't seem to be an obvious (to me anyway!) way to have an interface
> in .NET that passes an object [] such that it can be used by (say) VBScript.
> In other words, given a method:
>
> [ComVisible(true), GuidAttribute("66F12379-0C8F---------- etc")]
> [ClassInterface(ClassInterfaceType.AutoDispatch)]
> [ProgId("blah.blah")]
> public class Class1: IMyInterface
> {
> ..
> public void Connect(object [] initializeData )
>
> }
>
> What is required (MarshalAs or whatever) is that this kind of script works:

You don't need any special marschal instructions, because
the runtime already has a default marschaler for "object[]".

However, VBScript is not able to pass the expected SAFEARRAY
by value. It simply doesn't support that. You have to change
the managed signature from

    public void Connect(object [] initializeData )

to

    public void Connect(ref object [] initializeData )

>
> set obj = createobject("blah.blah")
> dim parm(2)
> parm (1) = "this"
> parm(2)="that"
>
> obj.Connect parm
>
> The error is pretty consistent at 0x800A0005 Invalid procedure call or
> argument: 'obj.Connect'

Rob