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

后端 未结 2 1949
礼貌的吻别
礼貌的吻别 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: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);
    

提交回复
热议问题