question

vbAtom avatar image
0 Votes"
vbAtom asked ·

How to prevent ComImport interface function reordering?

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-wpfdotnet-csharpdotnet-runtimedotnet-cli
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RLWA32-6355 avatar image
1 Vote"
RLWA32-6355 answered ·

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





· 4 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Super! Thanks! I will surly bare that in mind for future! LOL...lost all night in WTF is going on! LOL

Hm, If that is true...why to name functions same? LOL

(No, MIDL IDL and ZIDL... I'm running custom grabber tool that sniff and loosely translates it directly from *.h files into C#)
43350-interface-cpp-to-csharp-window-ymd-2020-11-27.png


0 Votes 0 ·


I modified tool and now ReorderSameNames function does it... it works like charm!

Thanks again @RLWA32-6355 !

0 Votes 0 ·

I suggest you carefully and comprehensively test the custom tool. In a very quick test I observed that the C++ vtable reordering of overloaded functions also occurs even if they are not grouped together in the related C++ header file.

1 Vote 1 ·
Show more comments