Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 859
Martin v. Löwis Avatar asked Aug 24 '26 10:08

Martin v. Löwis


2 Answers

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.

like image 78
ReinstateMonica Larry Osterman Avatar answered Aug 27 '26 00:08

ReinstateMonica Larry Osterman


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().

like image 41
Hans Passant Avatar answered Aug 26 '26 23:08

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!