windows-runtimec++-winrtwinrt-component

Can I add 'operations' to runtimeclass in a winrt component


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.


Solution

  • 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.