question

OgnjenMilic-3804 avatar image
0 Votes"
OgnjenMilic-3804 asked OgnjenMilic-3804 commented

Can I define parametrized type or method in MIDL 3.0

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

}

windows-uwpc++
· 2
5 |1600 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.

Please refer document here , you could define parametrized type.

0 Votes 0 ·

Hi,

I already went through that document. Heading "Parameterized Types" only advises about certain syntax errors and messages they produce. There is nothing about defining own parameterized types.

Regards,
Ognjen

0 Votes 0 ·

1 Answer

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered OgnjenMilic-3804 commented

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.


· 1
5 |1600 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.

Hi @NicoZhu-MSFT ,

Thanks for the answer. Now when I think abput it seems logical that it cannot be defined as it would make lots of complication in code generation due to nature of C++ templating.

Regards,
Ognjen

0 Votes 0 ·