How to prevent ComImport interface function reordering?

vb 276 Reputation points
2020-11-27T10:15:43.607+00:00

Hi!

I have strange problem while writing c# ComImport interface. Same name functions are reordered!?

Example....

In C++ IDCompositionVisual function order is:

STDMETHOD(SetOffsetX)(THIS_ float offsetX ) PURE
STDMETHOD(SetOffsetX)(THIS_ In IDCompositionAnimation* animation ) PURE
STDMETHOD(SetOffsetY)(THIS_ float offsetY ) PURE
STDMETHOD(SetOffsetY)(THIS_ In IDCompositionAnimation* animation ) PURE

and, if I set c# ComImport order like in C++, like this...

[PreserveSig] int SetOffsetX([In] Single offsetX);
[PreserveSig] int SetOffsetX([In] IDCompositionAnimation animation):
[PreserveSig] int SetOffsetY([In] Single offsetY);
[PreserveSig] int SetOffsetY([In] IDCompositionAnimation animation);

I get error calls in C#, crash!!!

When I have reordered same names functions like this...

[PreserveSig] int SetOffsetX([In] IDCompositionAnimation animation):
[PreserveSig] int SetOffsetX([In] Single offsetX);
[PreserveSig] int SetOffsetY([In] IDCompositionAnimation animation);
[PreserveSig] int SetOffsetY([In] Single offsetY);

then all calls are working!!!

How to prevent this from happening?
(This is happening for all same named functions)

Thanks in advance!
Vladimir

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,671 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
322 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,238 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,119 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 40,286 Reputation points
    2020-11-27T15:58:42.933+00:00

    COM does not support overloaded methods in an interface. If you tried to declare an overloaded method in the IDL for a COM object the MIDL compiler would complain about the redefinition and fail.

    There is a discussion about how the vtable pointers for overloaded C++ methods are reversed here - inversion-of-generated-vtable-functions-order-for-functions-with-the-same-name

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful