Can I define parametrized type or method in MIDL 3.0

Ognjen Milic 26 Reputation points
2021-08-01T23:42:59.75+00:00

Hi,

I am working on WinRT/C++ project and I am wondering if there is a way to define parametrized method in MIDL runtime class.

I would like to have something simillar to the following. I simplified the code as much as possible but it should explain the point.

class ServiceFactory {

template <typename T>
T getService<T>(const hstring& serviceName);

}

ServiceFactory sf;
....

ServiceX x = sf.getService<ServiceX>("X");

In MIDL file I would expect to be able to define something like this

runtimeclass ServiceFactory {

 <type T> T getService<T>();

}

Universal Windows Platform (UWP)
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,637 questions
{count} votes

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,861 Reputation points
    2021-08-03T05:50:51.14+00:00

    I am wondering if there is a way to define parametrized method in MIDL runtime class

    Please refer github readme Type System Specification - Methods. Methods may not be parameterized. And this Type System Specification - Runtime Classes said Runtime classes cannot be parameterized.

    Only interfaces and delegates may be parameterized. There is no syntax for defining a custom parameterized interface or delegate. All you can do is specialize an existing parameterized interface or delegate.


0 additional answers

Sort by: Most helpful