COM->.NET - can't access overloaded method

后端 未结 2 1944
礼貌的吻别
礼貌的吻别 2021-01-25 15:00

I\'m trying to access a .Net library (The Image Resizer) from COM (jscript).

I\'ve tried both IDispatch and class interface generation, as well as [ClassInterface( Clas

相关标签:
2条回答
  • 2021-01-25 15:24

    Overloading does not work for the interop layer to COM. You could however use optional parameters and hide all other methods from the COM layer:

    // COM won't see this.
    [ComVisible(false)]
    void Test(string a) 
    
    // COM will see this and parameter b is not required
    void Test(string a, [DefaultParameterValue(null)] string b)  
    
    0 讨论(0)
  • 2021-01-25 15:28

    True that COM doesn't "do" method overloading.

    BUT. see http://msdn.microsoft.com/en-us/library/ms182197(v=vs.80).aspx .

    This is a doc page on FxCop, a static analysis tool. But there's a tidbit of information there, which is useful for COM developers:

    When overloaded methods are exposed to COM clients, only the first method overload retains its name. Subsequent overloads are uniquely renamed by appending to the name an underscore character '_' and an integer that corresponds to the order of declaration of the overload.

    and also see
    Overloads in COM interop (CCW) - IDispatch names include suffix (_2, _3, etc)

    So, through the COM layer, you could call your original methods with

    Build_2("file", "file", s);
    Build_3("file", "file", settings);
    
    0 讨论(0)
提交回复
热议问题