vararg on dispinterface method not working
- From: Caddzooks <Caddzooks@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 20 Jan 2008 04:43:01 -0800
Hi.
I'm trying to implement a late-binding-only CCW that exposes a method that
must accept any number of arguments (passed as a Safearray of VARIANTS), and
the marshalling is not working.
The class below implments a CCW with a method that should accept a variable
number of arguments, that are received in an array.
However, this is not working. The scripting client is passing the args
correctly, but they are not accepted by the server, which is throwing an
exception (incorrect number of arguments).
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ScriptLib
{
/// IDL:
///
// dispinterface IScriptLet {
// properties:
// methods:
// [id(0x00000001), vararg]
// VARIANT Method1([in] SAFEARRAY(VARIANT) args);
// };
// VBA Test code:
//
// Public Sub test()
// Dim target As Object
// Set target = New ScriptLib.ScriptLet
// Dim oResult As Object
// oResult = target.Method1(1, 2, 3)
// End Sub
[ComVisible( true )]
[InterfaceType( ComInterfaceType.InterfaceIsIDispatch )]
public interface IScriptLet
{
[DispId( 0x1 )]
object Method1( [In, MarshalAs( UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_VARIANT )] params object[] args );
}
[ComVisible( true )]
[ProgId( "ScriptLib.ScriptLet" )]
[ComDefaultInterface( typeof( IScriptLet ) )]
[ClassInterface( ClassInterfaceType.AutoDispatch )]
public class ScriptLet : IScriptLet
{
[DispId( 0x1 )]
public object Method1( [In, MarshalAs( UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_VARIANT )] params object[] args )
{
Console.WriteLine( "args: {0}", args.GetType() );
return null;
}
}
}
.
- Follow-Ups:
- Re: vararg on dispinterface method not working
- From: Caddzooks
- Re: vararg on dispinterface method not working
- Prev by Date: Debugging vb6 from ASP.NET
- Next by Date: Hosting Preview Handler In DotNet Application?
- Previous by thread: Debugging vb6 from ASP.NET
- Next by thread: Re: vararg on dispinterface method not working
- Index(es):