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?
Static methods on a winrt interface are implemented as interfaces off the class factory for that class.
For this case, you should call (much winrt overhead elided):
ComPtr<IDatagramSocketStatics> factory;
HRESULT hr = RoGetActivationFactory(<HSTRING for Windows.Networking.Sockets.DatagramSocket>, __iidof(IDatagramSocketStatics), &factory.GetAddressOf());
hr = factory->DatagramFactoryMethod(<Parameters>);
As I mentioned, this is pseudo-code, but it should be sufficient to see how to call the static methods.
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With