Search code examples
uwpdesktop-bridgewindows-10-desktop

Use newer Windows 10 API in desktop apps


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.


Solution

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