Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown in BluetoothLE sample using c++ #1210

Closed
hayesgreg opened this issue Jun 3, 2020 · 3 comments
Closed

Exception thrown in BluetoothLE sample using c++ #1210

hayesgreg opened this issue Jun 3, 2020 · 3 comments

Comments

@hayesgreg
Copy link

I'm writing a program to automatically test a BluetoothLE device I have developed. To get started I downloaded the BluetoothLE sample app from https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/BluetoothLE and got the cs program working ok, however I cannot get the c++ program to work.

The app builds ok and I can run it on a remote PC with Remote Machine Debuging. The app starts ok and in scenario1_Discovery enumerates a BluetoothLE Heart Rate Moniter (HRM).
I select the HRM and go to scenario2_Client, click connect and the HRM connects.
The Service comboBox shows and I can click on HeartRateService ok.
The Characteristic comboBox shows but when I click on HeartRateMeasurement characteristic the program crashes with Exception error and the following message:

  • Exception thrown at 0x76734402 (KernelBase.dll) in BluetoothLE.exe: WinRT originate error - 0x80004002 : 'No such interface supported'.
  • Exception thrown at 0x76734402 in BluetoothLE.exe: Microsoft C++ exception: winrt::hresult_no_interface at memory location 0x03A9CEA0.
  • Debug Error!
  • Program: ...SDKSamples.BluetoothLE.CPPVS.Debug_Win32.Greg\BluetoothLE.exe

It appears to fail on line 313 of Scenario2_Client.cpp
selectedCharacteristic = selectedItem ? selectedItem.Tag().as() : nullptr;

Scenario2_Client.cpp:

fire_and_forget Scenario2_Client::CharacteristicList_SelectionChanged()
    {
        auto lifetime = get_strong();
	auto selectedItem = ServiceList().SelectedItem().as<ComboBoxItem>();
        
313     selectedCharacteristic = selectedItem ? selectedItem.Tag().as<GattCharacteristic>() : nullptr;
        
        if (selectedCharacteristic == nullptr)
        {
            EnableCharacteristicPanels(GattCharacteristicProperties::None);
            rootPage.NotifyUser(L"No characteristic selected", NotifyType::ErrorMessage);
            co_return;
        }
	.
        .
        .
  }

Can I get help solving this problem please. I'm new to c++ so finding it difficult.

Win 10.0.18363.836
VS Community 2019 Version 16.6.1
Thanks, Greg

@alexredko
Copy link

alexredko commented Nov 27, 2021

The bug is at the line
auto selectedItem = ServiceList().SelectedItem().as<ComboBoxItem>();
There shoud be CharacteristicList instead of ServiceList :
auto selectedItem = CharacteristicList().SelectedItem().as<ComboBoxItem>();

@galaxy-tek
Copy link

great, thanks for your answer.
i have got stuck in this issue for several days.
how can Microsoft publish such a bug demo!

@oldnewthing
Copy link
Member

oldnewthing commented May 25, 2022

Sorry. The Bluetooth team wrote the C# sample, and I translated it to C++/WinRT. I'm good with C++/WinRT but I don't work on Bluetooth, so I just translate it as best I can and sometimes I mess up.

Fix is available in ad9a0c4 v13.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants