Задайте вопросЗадайте вопрос
 

ОтвеченоParams array does not work with COM Interop

  • 5 января 2009 г. 22:17Christoph Wienands Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    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

Ответы

Все ответы