Home > Net >  How to register radio StateChange event using C WinRT API
How to register radio StateChange event using C WinRT API

Time:09-22

// Register
event_token StateChanged(TypedEventHandler<Radio, IInspectable const&> const& handler) const;

Can anyone please help with the code to register the events using C winRT. I'm looking for the code which can call the event when the radio state is changed

CodePudding user response:

Can anyone please help with the code to register the events using C winRT.

You could refer to official sample code, and Register event like the following.

myRadioStateChangedToken = MyRadio.StateChanged({ get_weak(), &Scenario1_Discovery::MyRadio_StateChanged});

For more detail about Handle events by using delegates in C /WinRT. please refer to this tutorial.

CodePudding user response:

    void Radio_StateChanged(Radio const& sender, winrt::Windows::Foundation::IInspectable const& args) {
    printf( "\t Radio_StateChanged \n");
}
    
    
    void radio_register_function(){
    IVectorView<Radio> radios3 = Radio::GetRadiosAsync().get();//trying to get mobilebroadband object
    for (Radio const& radio : radios3)
    {
        if (radio.Kind() == RadioKind::MobileBroadband)
        {
            auto rad = radio.StateChanged(&Radio_StateChanged);//registering for event
            break;
        }
    }
}

I'm not getting any compilation error but when I try to enable or disable the radio, the function RadioStateChanged is not called(event not triggered)

  • Related