Search code examples
interfacewindows-runtimeidl

IDL static interfaces


For WinRT, IDL now supports constructs such as this:

[marshaling_behavior(agile)]
[threading(both)]
[activatable(0x06020000)]
[version(0x06020000)]
[static(Windows.Networking.Sockets.IDatagramSocketStatics, 0x06020000)]
runtimeclass DatagramSocket
{
    [default] interface Windows.Networking.Sockets.IDatagramSocket;
    interface Windows.Foundation.IClosable;
}

I'm curious about the static attribute. What does it mean? How does it relate to the interfaces listed inside the body of the runtimeclass?


Solution

  • COM does not support the notion of static methods of a class, all methods must be instance methods since interface methods are abstract. The attribute allows the language projection to emulate static behavior of a method. Specifically the DatagramSocket.GetEndpointPairsAsync() overloads.

    Notable as well is that COM also doesn't support overloads, also solved with an attribute. The methods of IDatagramSockeStatics have the [overload] attribute, the real name of the 2nd overload is GetEndpointPairsWithSortOptionsAsync().