IT 专业人士的资源 > 论坛主页 > Interoperability Conversations (Archived) > Params array does not work with COM Interop
提出问题提出问题
 

已答复Params array does not work with COM Interop

  • 2009年1月5日 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

答案

  • 2009年1月5日 22:41Christoph Wienands 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    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
  • 2009年1月15日 22:51Chris MullaneyMSFT, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    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

全部回复

  • 2009年1月5日 22:41Christoph Wienands 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    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
  • 2009年1月15日 22:51Chris MullaneyMSFT, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复
    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