471,599 Members | 1,811 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,599 software developers and data experts.

using MSSCriptControl with C#, params keyword question

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
Nov 17 '05 #1
1 3943
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

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by trapeze.jsg | last post: by
reply views Thread by 2G | last post: by
1 post views Thread by fred_mumble | last post: by
1 post views Thread by Michael Kremser | last post: by
8 posts views Thread by David Duerrenmatt | last post: by
2 posts views Thread by csperler | last post: by
7 posts views Thread by Bill H | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.