0

In the below code "RuntimeMethod1()" is an operation. It does not take any input parameters and does not give back any result. Is this kind of method allowed in a runtime class?

I am getting compilation error for this runtime class. It says

expecting an identifier near "(" at line 7

namespace UniversalRuntimeComponent  
{  
    [default_interface]  
    runtimeclass Class  
    {  
        Class();  
        RuntimeMethod1();  
        Int32 RuntimeMethod2(Int32 arg1);  
        String RuntimeMethod3(String arg1);  
    }  
}

If I remove "RuntimeMethod1()" from the class then it compiles fine and generates the projection and implementation types.

vikas pachisia
  • 553
  • 5
  • 8

2 Answers2

1

If it doesn't return a result then make its return type void.

Change line 7 in your IDL to the following:

void RuntimeMethod1(); 

Then either copy and paste the method from auto generated .h file or just add it manually.

M. Abelson
  • 98
  • 7
  • Although this works, I was looking for the runtime equivalent of void. This is because other datatypes such as Int32, String etc. is defined in Windows::Foundation. Using WinRT types will help in generating the right types for the right platform. Also, the Windows::Foundation define a type called 'Empty' which is not void. Is c/cpp 'void' type the only way out? – vikas pachisia Aug 12 '19 at 05:43
  • The RuntimeMethod1() operation you wrote seems like a method call instead of a declaration.The datatypes Int32, String isn't defined in Windows::Foundation,it will find it's relevant projected type when compiles(like String->winrt::hstring).I don't find the "Empty" type in Windows::Foundation.When describing a method that does not return a value, it can only be modified with void. – Faywang - MSFT Aug 12 '19 at 10:05
1

With the exception of constructors, all methods in MIDL 3.0 need to declare a return type. The documentation has the following to say on methods:

A method has a (possibly empty) list of parameters, which represent values or variable references passed to the method. A method also has a return type, which specifies the type of the value computed and returned by the method. A method's return type is void if it doesn't return a value.

You will have to change the MIDL to the following:

namespace UniversalRuntimeComponent  
{  
    [default_interface]  
    runtimeclass Class  
    {  
        Class();  
        void RuntimeMethod1();  
        Int32 RuntimeMethod2(Int32 arg1);  
        String RuntimeMethod3(String arg1);  
    }  
}

Note, that the data types declared in MIDL follow MIDL specification. This is not strictly related to the Windows Runtime type system, although all MIDL data types map to data types that can be represented in the Windows Runtime type system.

Also note, that all methods in the Windows Runtime have at least one return value at the ABI. A method declared using void in MIDL will still return an HRESULT to communicate error or success.

IInspectable
  • 46,945
  • 8
  • 85
  • 181
  • All agreed, but from a syntactic point of view, I would have been happy to use something like VOID, PVOID instead of the void. When MIDL has defined types such as Int32 which is nothing but int and String which gets mapped appropriately based on the consumer, then why not define VOID? – vikas pachisia Aug 14 '19 at 08:56
  • I understand that there is no option but to use void and no point in arguing about it, But I wanted to bring it to notice so that the MIDL team can think about it. In the excerpt you posted it says "A method's return type is void if it doesn`t return a value" and I am saying that give me a syntax to denote that the return type is void something in the lines of Int32 and String. – vikas pachisia Aug 14 '19 at 08:57
  • You seem to be confusing the purpose of MIDL: It's an interface definition language, that's not related to C++ (or any other programming language). An `Int32` in MIDL is required to use two's complement representation; an `int` in C++ is not. Likewise, a `Single` in MIDL is required to use IEEE representation. Again, a `float` in C++ is not. I'm not sure what you would like to be changed. `void` is the keyword used to designate a method, that does not return a value. What should the MIDL team change, and which problem needs to be solved? Making the parser more complex requires a good reason. – IInspectable Aug 14 '19 at 10:56
  • I understand those concepts quiet well and I am not arguing on those aspects. I am just talking about the completeness of the language. It is like, there are typedefs for void and void* and developers use VOID and PVOID. Why do we need to have void and void* typedefs? The point is, be it a type or the keyword It should have a sense of belonging to MIDL especially when similar keywords and types have that sense of belonging while also resembling c++ language. The color above is talking about syntax. Anyways the topic is not worth investing time in. So I would like to stop the discussion here. – vikas pachisia Aug 16 '19 at 07:40