 |
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Mon Feb 23, 2009 8:58 am
COM parameter passing problem. |
if an application has a method with the following signature:
Code: |
public string MethodName(string Param1, params object[] Param2)
|
it will never see the method invocation because CMUD rejects such parameter passing.
I've made some extensive tests and come to the conclusion that the problem is on the CMUD side.
For instance, if I change the signature to:
Code: |
public string MethodName(string Param)
|
it will work just fine, but this
Code: |
public string MethodName(params object[] Param)
|
will not work. So for some reason CMUD does not like the signature.
One of the reasons I think this is the case because while using Darkhael's SQlite3 script interface. He makes the claim that this will work:
Code: |
$stringvar = "... SOME SQL STATEMENT..."
;;
#VAR arrayvar %array(param1,param2,...,paramN)
;;
$rec = @comobj.Execute($stringvar, @arrayvar)
|
However, this doesn't seem to work either. The only way I've gotten it to work is by doing this:
Code: |
....
....
$rec = @comobj.Execute($strigvar,%array(param1,param2,...paramN))
....
|
That is, by explictly declaring the array in the parameter list.
So some confusion must be taking place. In the case of the method signature, the fact that an object[] array is declared when, in fact, none of the parameters passed to the application is an array, has the parser reject the call. Tests show that the rejection is done by the caller, not the application. The application never sees the call.
Tests of the problem signature using both a Windows interface and the command line, ran successfully. This indicates that COM has no problem with it. This could be because by the time the invocation gets to the interface from CMUD, something has been changed.
NOTE: That is the only way to have a method accept a variable number of (possibly) mixed parameters. |
|
_________________ Sic itur ad astra. |
|
|
 |
Zugg MASTER

Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Feb 23, 2009 5:34 pm |
Is there some COM interface available that can be used to test this? I looked into this and I don't see any difference between creating the %array with #VAR and passing it, or with putting the %array inline. The only thing that could mess this up is if you do something to the #VAR that causes it's type to change.
%array is the proper function to use. It generates a COM array and is intended to be used in the way that you mentioned. You cannot use any other variable type in it's place. COM arrays are very specific in how they are implemented, and that is what %array is for.
In any case, I don't have any way to test any problem with this. If you have a COM DLL that can be used to demonstrate the problem, let me know. Or better would be to give an example for a COM object that comes with Windows, or give the link to the SQLite3 script that you mentioned. |
|
|
 |
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Tue Feb 24, 2009 2:13 am |
I apologize for posting two problems in one thread. I mention the problem with Darkhael's SQlite3 COM interface because as you can tell by looking at his posted script here, the Execute method, invoked by @comobj.Execute(....), has a signature of Execute (sql,*args). This signature is equivalent to the method signature for the COM object I mentioned above. i.e
Code: |
public string MethodName(string Param1, params object[] Param2) |
The second parameter in my signature is equivalent to Darkhael sqlite3 script's *args. His works (for the most part, as I mentioned I am having problems passing arrays), mine doesn't.
I believe two things are taking place here: His works because his script is a windows script (.wsc), while mine is written in C#. Also, while I mention that his method signature and mine are equivalent, his second parameter does not look like an array unless one (the parser) knows that it is looking at a Python script. Of course, this is an schematic parameter anyway. It is designed to wrap a variable list of parameters without having to explicitly mention how many. So while the caller passes a C/S list, the method sees it as an array.
Note that
Code: |
public string MethodName(string Param1, params object[] Param2)
|
and
Code: |
public string MethodName(params object[] Param)
|
are processed exactly the same way. In the first example, the first parameter is both named and typed, while in the second example it has to be extracted and its type investigated. Both of these equivalent signatures are rejected when invoked from CMUD, but not from Windows or the command line. From those two points, they work just fine.
To test sqlite3 with Darkhael's code, just install the script. To test my problem directly, a small COM wrapper can be written with a method that has the problem signature. A "Hello World" would do just fine, because, if I am right, it will never get executed. At this point I haven't used neither Basic, C, nor C++ for my test, only C#. However, under the .NET framework they would appear the same from the outside. |
|
_________________ Sic itur ad astra. |
|
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|