473,670 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(VARIA NT) p);

I have checked an existing function in MSScriptControl ocx, and a similar
function having this feature has this signature:

[id(0x000007d3), vararg, helpstring("Cal l a procedure defined in the
module"), helpcontext(0x0 0113f09)]
HRESULT Run([in] BSTR ProcedureName, [in] SAFEARRAY(VARIA NT)* 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 4078
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({0F21F35 9-AB84-41E8-9A78-36D110E6D2F9}, "VBScriptProj.C lass1")
]
interface _Class1 : IDispatch {
[id(00000000), propget,
custom({54FC8F5 5-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(VARIA NT) 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( ClassInterfaceT ype.AutoDual)]
public class Class1
{
public Class1()
{
}
public int TryFunc1(string a)
{
MessageBox.Show ("Class1::TryFu nc1");
return 555;
}
public int TryFunc2(string a, params object[] p)
{
MessageBox.Show ("Class1::TryFu nc2");
return 777;
}
}

-------------------------------------------

This is the VBScript code:

-------------------------------------------

set obj = CreateObject("V BScriptProj.Cla ss1")
obj.TryFunc2 "aaa"

-------------------------------------------

This is the error message:
---------------------------
Windows Script Host
---------------------------
Script: C:\Projects\a\V BScriptProj\bin \Debug\VBScript Proj.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******** ******@TK2MSFTN GP10.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(VARIA NT) p);

I have checked an existing function in MSScriptControl ocx, and a similar
function having this feature has this signature:

[id(0x000007d3), vararg, helpstring("Cal l a procedure defined in the
module"), helpcontext(0x0 0113f09)]
HRESULT Run([in] BSTR ProcedureName, [in] SAFEARRAY(VARIA NT)* 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
3282
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 be OK. The problem I am facing is that I can't seem to authenticate myself. I have made a small change to ZSI.client so that when I get a "401 Unauthorized" response from the remote server I build up a nice authorization request:
0
1013
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 - not supported - param is omitted in parsing and param is then an ordinary array type param Thanks.
1
5560
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 report being generated based on test parameters input by a user - 4 batches of scripts containing multiple functions will be run each time a user runs a new test. The reason the scripts are run in 4 batches is due to the fact that each batch is...
1
8779
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 MSScriptControl.ScriptControlClass(); myScriptingEngine.AllowUI = false; myScriptingEngine.Language = "VBScript";
8
3168
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, the list/tuple named params will automatically be "expanded" and
2
2501
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 method are not put into an array, so the method signature never matches the object array of parameters. Is there another way around this without explicitly creating an array (a la new object {new int {1, 2, 3}})? class A
7
4039
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 DataTable(); SqlDataAdapter.Fill(dt); 'dt' is passed by ref, but it is not required to pass it as such: SqlDataAdapter.Fill(ref dt);
0
1948
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 of string manipulation where they seek through the string back and forth doing replacements to substitute in the needed HTML code. I am convinced that this can be done with a few regular expressions. Unfortunately my knowledge of regular...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5686
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.