Hi All,
it's me again :-). I have simplified the problem a lot. So my purpose is
still to use variable number of arguments in a function signature for a c#
function that gets invoked from vbscript. I have done two simple projects,
one in C++, the other in C#. looking at the type library, the function
signatures are the same, here is the relevant part of the C# tlb:
-----------------------------------------
[
odl,
uuid(9BDA5AAE-360F-34DC-8951-A31AEFA92DD1),
hidden,
dual,
nonextensible,
oleautomation,
custom({0F21F359-AB84-41E8-9A78-36D110E6D2F9}, "VBScriptProj.Class1")
]
interface _Class1 : IDispatch {
[id(00000000), propget,
custom({54FC8F55-38DE-4703-9C4E-250351302B1C}, "1")]
HRESULT ToString([out, retval] BSTR* pRetVal);
[id(0x60020001)]
HRESULT Equals(
[in] VARIANT obj,
[out, retval] VARIANT_BOOL* pRetVal);
[id(0x60020002)]
HRESULT GetHashCode([out, retval] long* pRetVal);
[id(0x60020003)]
HRESULT GetType([out, retval] _Type** pRetVal);
[id(0x60020004)]
HRESULT TryFunc1(
[in] BSTR a,
[out, retval] long* pRetVal);
[id(0x60020005), vararg]
HRESULT TryFunc2(
[in] BSTR a,
[in] SAFEARRAY(VARIANT) p,
[out, retval] long* pRetVal);
};
-------------------------------------------
VBScript does work for the C++ project, and does not for the C# project.
This is my C# code:
-------------------------------------------
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Class1
{
public Class1()
{
}
public int TryFunc1(string a)
{
MessageBox.Show("Class1::TryFunc1");
return 555;
}
public int TryFunc2(string a, params object[] p)
{
MessageBox.Show("Class1::TryFunc2");
return 777;
}
}
-------------------------------------------
This is the VBScript code:
-------------------------------------------
set obj = CreateObject("VBScriptProj.Class1")
obj.TryFunc2 "aaa"
-------------------------------------------
This is the error message:
---------------------------
Windows Script Host
---------------------------
Script: C:\Projects\a\VBScriptProj\bin\Debug\VBScriptProj. vbs
Line: 2
Char: 1
Error: Invalid procedure call or argument: 'obj.TryFunc2'
Code: 800A0005
Source: Microsoft VBScript runtime error
---------------------------
OK
---------------------------
Please tell me what to do.
Thank you,
Jozsef
"Jozsef Bekes" <bj****@hotmail.com> wrote in message
news:e3**************@TK2MSFTNGP10.phx.gbl...
Hi All,
I need to offer scripting possibilities in my app, and have to use
MSSCriptControl for some reasons. I would like to use the feature that's
called variable number of arguments, that is done in C# using the params
keyword. However, if I AddObject the instance to the MSScriptControl, and
try to ivoke a function with variable number of arguments, the script
throws an exception. I have exported the class signatrure to a tlb file,
and checked the signature. The C# function is exported like this:
[id(0x60020007), vararg] HRESULT ParamListTester( [in] BSTR s, [in]
SAFEARRAY(VARIANT) p);
I have checked an existing function in MSScriptControl ocx, and a similar
function having this feature has this signature:
[id(0x000007d3), vararg, helpstring("Call a procedure defined in the
module"), helpcontext(0x00113f09)]
HRESULT Run([in] BSTR ProcedureName, [in] SAFEARRAY(VARIANT)* Parameters,
[out, retval] VARIANT* pvarResult);
The only difference seems to be the * in the parameter definition, but I
cannot see a way to implement it in C#. Can anyone help me with that?
Thank you,
Jozsef