locked
Params array does not work with COM Interop RRS feed

  • Question

  • Hello everybody,

    My main problem is that I cannot get methods with params array parameters working when they are called from a scripting language such as JavaScript.

    Details: I'm stuck with a JavaScript/C# interop problem when using the WebBrowser control. I assign a C# object to the Webbrowser.ObjectForScripting property. Now, any JavaScript can access this object through 'window.external' and call methods and read/write properties. The class definition for this object is attributed with ComVisible.

    This all works fine for methods with a fixed amount of parameters. However, I have to provide methods that accept an unlimited number of parameters. In C# this is done with the 'params object[]' construct. However, COM doesn't like this. From what I found out so far I think that this cannot be accomplished using an early-bound COM interface. Rather, when looking from a pure COM persepctive my object needs to implement the IDispatch interface. Then the IDispatch.Invoke method accepts any number of parameters.

    I have searched the Internet for quite a while but could not find much relevant information. There are bits and pieces such as the DispId attribute but I don't see how this could fit my particular problem.

    Hare a couple of questions that are floating around and whose answers might help soving the issue at hand...
    -How does VB6 achieve variable number of parameters, especially when no late-binding is used?
    -If I have to implement a C# method that accepts an array of variants (or so), will the scripting client still be able to use a syntax like 'object.method(var1, var2, var3,...)
    -Is it possible or required to implement IDispatch manually in C#? Or can some of the Interop attributes be used to achieve the 'params' effect for the scripting client?

    Phew, so many questions, so few answers ;-) Thanks a lot for your sharing thoughts,

    Christoph
    Monday, January 5, 2009 10:17 PM

Answers

  • Well, I guess this is not the right forum. So that most other questions are just closed with a generic 'wrong forum' message. I'd recommend choosing a better description for the forum on the forum overview page.

    Regards, Christoph
    Monday, January 5, 2009 10:41 PM
  • Thank you Christoph. We are planning to change the structure and naming of our interoperability forums soon, in part to address confusion with the naming as you've noted. When we make this change, we'll post the change on this forum as well for your future reference.

    Chris
    • Marked as answer by Chris Mullaney Thursday, January 15, 2009 10:51 PM
    Thursday, January 15, 2009 10:51 PM

All replies

  • Well, I guess this is not the right forum. So that most other questions are just closed with a generic 'wrong forum' message. I'd recommend choosing a better description for the forum on the forum overview page.

    Regards, Christoph
    Monday, January 5, 2009 10:41 PM
  • Thank you Christoph. We are planning to change the structure and naming of our interoperability forums soon, in part to address confusion with the naming as you've noted. When we make this change, we'll post the change on this forum as well for your future reference.

    Chris
    • Marked as answer by Chris Mullaney Thursday, January 15, 2009 10:51 PM
    Thursday, January 15, 2009 10:51 PM