COM Communication Overloads (CCWs) - IDispatch names include the suffix (_2, _3, etc.)

I have a managed assembly containing several classes, and these classes have overloaded methods. I provide assembly to callers COM / IDispatch through

[ComVisible(true)]

.., and also install the correct Guid on the assembly itself. I do not define an explicit interface for COM interoperability. All this is done dynamically. I run regasm.exe /codebasein a managed DLL and register it for COM interaction.

When I launch OleView, I can see the ProgId of various classes in the assembly. But looking through these ProgIds and expanding the IDispatch node, there is no TypeLib information for these classes.

However, from a script, I can call a method that takes null arguments or a method that takes a single argument. If there is an overload that takes more than one argument, I cannot call this method by name. The error I get is sequentially

Microsoft VBScript runtime error: Wrong number of arguments or invalid property assignment:  <methodname>

From this, I realized that the COM / IDispatch clients were not able to correctly resolve the overloaded methods for an object opened through COM interaction.


Then i added

[ClassInterface(ClassInterfaceType.AutoDual)]

... to each of the classes in question. After regasm.exein the DLL, I can see typelib information for each method in the IDispatch node.

I found that overloaded methods automatically get a name that includes the suffix with the append. MethodX will expose overloads in the automatically generated typelib assembly like MethodX, MethodX_2, MethodX_3, etc.

, , , , .

, [ClassInterface(ClassInterfaceType.AutoDual)] , , Wrong number of arguments or invalid property assignment.

: - - ? ? ?

+2
3

COM , .NET COM Interop . , , , , , , - - API COM. COM, - COM- [ComVisible] . COM- [Optional] ( .NET).

+5

, interop generate Method, Method_1, Method_2 .. , . , / . , , COM-Visible , COM , .

+1

, MSDN:

"" , , , "". , , .

, COM , . .NET- , :

// used for binary-compatibility with .NET clients who currently use 
// the old, one-parameter version
[ComVisible(false)]
void myMethod(String oneParameter) {   
    ... 
}   

// since this is the first COM-visible version, it is assigned the "correct" name.
void myMethod(String oneParameter, int newParameter = 0) {
    ...
}

COM , myMethod(string), myMethod(string, int).

+1

Source: https://habr.com/ru/post/1526417/


All Articles