473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 4064
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: trapeze.jsg | last post by:
Hi. I am trying to get through to Microsoft MapPoint Services using ZSI for soap handling. I can generate the service classes and also the soap-requests generated by the service classes seem to...
0
by: 2G | last post by:
Hi I'm try to generate params SqlParameter commandParameters but I can't get the params in there. Is it possible that it is not supported? I've read this on a webpage somewhere: params keyword...
1
by: fred_mumble | last post by:
I have been testing various techniques to run "script" code which will be stored in a SQL database and executed dynamically at runtime. The scripts are essentially business rules that result in a...
1
by: Michael Kremser | last post by:
Hi NG! I have converted a running VS.net 2003 solution to VS.net 2005 Beta 2 (Version 8.0.50215.44) and tried to compile it. This is the code: myScriptingEngine = new...
8
by: David Duerrenmatt | last post by:
Hi there For some reasons, I've to use Python 1.5.2 and am looking for a workaround: In newer Python versions, I can call a function this way: func = some_function func(*params) Then,...
2
by: csperler | last post by:
Hi There - The code that follows does not work. I'm trying to dynamically invoke a method that contains a params-attributed parameter. However, the array of objects that are passed into the...
7
by: Bill H | last post by:
i'm new to C#... How can I create an out or ref param for a method without having to declare it in the caling code ? Like the DataAdapter can do on its Fill method. DataTable dt = new...
0
by: peridian | last post by:
Hi, I wanted a web page where I could post code to, and have it appear in coloured formatting based on the context of the code. Most of the techniques I have seen for this involve complex use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.