1

We're developing a desktop app that needs Bluetooth LE connectivity. It is possible to use the Windows 10 Bluetooth API in desktop apps, but there is no access to newer API features as far as I can tell.

The type BluetoothAdapter for instance cannot be accessed from a Windows 10 desktop app with the UwpDesktop nuget package installed. Is there some other way to access newer Windows 10 features? The specific feature we're after is BLE GATT services without pairing.

Wouter
  • 2,170
  • 1
  • 28
  • 58

1 Answers1

0

You can use newer Windows 10 APIs by referencing the winmd files from newer Windows 10 SDKs. The standard set of references are listed on https://learn.microsoft.com/en-us/windows/uwp/porting/desktop-to-uwp-enhance

This means the latest SDK binaries can be found in the following locations:

C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD
C:\Program Files (x86)\Windows Kits\10\References\10.0.17134.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd
C:\Program Files (x86)\Windows Kits\10\References\10.0.17134.0\Windows.Foundation.UniversalApiContract\6.0.0.0\Windows.Foundation.UniversalApiContract.winmd
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.UI.Xaml.dll

To find out if a certain API is supported you need to check if it has the DualApiPartitionAttribute attribute.

Wouter
  • 2,170
  • 1
  • 28
  • 58
  • Just a note - the `DualApiPartition` attribute is a hint but it's not perfect... some things that don't have the attribute will still work. – Peter Torr - MSFT May 21 '18 at 01:16
  • @PeterTorr-MSFT does that also apply the other way around? Using DevicePicker in a desktop always throws an exception even though it has said interface. – Wouter May 21 '18 at 10:14
  • Yes but that sounds like a bug. Which specific API is failing? – Peter Torr - MSFT May 21 '18 at 17:57
  • `DevicePicker.PickSingleDeviceAsync` (and other UI calls) throw the following exception: "Interface not registered (Exception from HRESULT: 0x80040155)" – Wouter May 22 '18 at 08:08
  • There are some problems with using WinRT that way. It is better to import WinRT interfaces from headers and use it as simple COM interfaces. But it requires lot of coding. You can save you time using Bluetooth Framework. – Mike Petrichenko May 22 '18 at 11:00