Skip to content

Commit 0821958

Browse files
committed
Windows 11 Version 24H2 - July 2025 Samples Update
2 parents 61b4d32 + 534d40a commit 0821958

File tree

103 files changed

+6801
-2426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+6801
-2426
lines changed

Samples/BasicHologram/cs/BasicHologram.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
<Import Project="ms.fxcompile.targets" />
130130
<ItemGroup>
131131
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
132-
<Version>5.2.2</Version>
132+
<Version>5.2.4</Version>
133133
</PackageReference>
134134
<PackageReference Include="SharpDX">
135135
<Version>3.0.2</Version>

Samples/BluetoothAdvertisement/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,29 @@ This sample allows the user to publish and watch for Bluetooth Low Energy advert
4040
- **Background watcher**: Scanning for a particular LE advertisement containing a matching manufacturer data section and above a certain RSSI threshold using a background trigger and task.
4141
- **Background publisher**: Publishing a LE advertisement in the background. The advertisement generated by this scenario can be received by running Scenario 1 or 3 on another Windows platform in close proximity with this one.
4242

43+
This sample also detects and offers to take advantage of the ability to advertise Bluetooth LE advertisements and scan for Bluetooth LE advertisements using both the 1M, 2M, and Coded PHYs, use coexistence-optimized Bluetooth LE advertisement scanning, and offload Bluetooth LE advertisement filtering to hardware.
44+
4345
**Note:** A working Bluetooth dongle/radio is needed in order to test this sample's functionality. The VS Emulator is a valid target, but since there's technically no valid Bluetooth, the app will treat it as if there's no Bluetooth radio and beacon functionality cannot be used.
4446

4547
## Related topics
4648

4749
### Related samples
4850

49-
* [BluetoothAdvertisement sample](/archived/BluetoothAdvertisement/) for JavaScript (archived)
51+
* [BluetoothAdvertisement sample](/archived/BluetoothAdvertisement/) for JavaScript and Visual Basic (archived)
5052

5153
## System requirements
5254

53-
* Windows 10
55+
Windows 10 Version 1703 (build 15063) for basic functionality.
56+
57+
Windows 11 build 26100 for 1M and 2M PHY functionality.
5458

5559
## Build the sample
5660

61+
**Note**: This sample requires Windows SDK version 10.0.26100.3916 or higher.
62+
Unfortunately, there is no way to detect the 3916 revision at build time.
63+
If you get errors about undefined members like `IsLowEnergyUncoded2MPhySupported`,
64+
make sure you have installed a high enough version of the Windows SDK.
65+
5766
1. If you download the samples ZIP, be sure to unzip the entire archive, not just the folder with the sample you want to build.
5867
2. Start Microsoft Visual Studio and select **File** \> **Open** \> **Project/Solution**.
5968
3. Starting in the folder where you unzipped the samples, go to the Samples subfolder, then the subfolder for this specific sample, then the subfolder for your preferred language (C++, C#, or JavaScript). Double-click the Visual Studio Solution (.sln) file.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
6+
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
7+
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
8+
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9+
//
10+
//*********************************************************
11+
12+
#include "pch.h"
13+
#include "BackgroundTasks.h"
14+
#include "AdvertisementWatcherTask.g.cpp"
15+
#include "AdvertisementPublisherTask.g.cpp"
16+
#include "SampleConfiguration.h"
17+
#include <chrono>
18+
#include <sstream>
19+
20+
namespace winrt
21+
{
22+
using namespace winrt::Windows::ApplicationModel::Background;
23+
using namespace winrt::Windows::Devices::Bluetooth;
24+
using namespace winrt::Windows::Devices::Bluetooth::Background;
25+
using namespace winrt::Windows::Devices::Bluetooth::Advertisement;
26+
using namespace winrt::Windows::Foundation;
27+
using namespace winrt::Windows::Foundation::Collections;
28+
using namespace winrt::Windows::Globalization::DateTimeFormatting;
29+
using namespace winrt::Windows::Storage;
30+
using namespace winrt::Windows::Storage::Streams;
31+
}
32+
33+
namespace winrt::SDKTemplate::implementation
34+
{
35+
std::wstring FormatOptionalInt16(IReference<int16_t> const& value)
36+
{
37+
if (value)
38+
{
39+
return std::to_wstring(value.Value());
40+
}
41+
else
42+
{
43+
return L"none";
44+
}
45+
}
46+
47+
std::wstring FormatOptionalTimeSpanMs(IReference<TimeSpan> const& span)
48+
{
49+
if (span)
50+
{
51+
return std::to_wstring(std::chrono::duration_cast<std::chrono::milliseconds>(span.Value()).count());
52+
}
53+
else
54+
{
55+
return L"none";
56+
}
57+
}
58+
59+
/// <summary>
60+
/// The entry point of a background task.
61+
/// </summary>
62+
/// <param name="taskInstance">The current background task instance.</param>
63+
void AdvertisementWatcherTask::Run(IBackgroundTaskInstance const& taskInstance)
64+
{
65+
watcherTaskInstance = taskInstance;
66+
67+
auto details = taskInstance.TriggerDetails().as<BluetoothLEAdvertisementWatcherTriggerDetails>();
68+
69+
// In this example, the background task simply constructs a message communicated
70+
// to the App. For more interesting applications, a notification can be sent from here instead.
71+
std::wostringstream ss;
72+
73+
// If the background watcher stopped unexpectedly, an error will be available here.
74+
BluetoothError error = details.Error();
75+
if (error != BluetoothError::Success)
76+
{
77+
ss << L"Error: " << to_hstring(error) << L", ";
78+
}
79+
80+
// The Advertisements property is a list of all advertisement events received
81+
// since the last task triggered. The list of advertisements here might be valid even if
82+
// the Error status is not Success since advertisements are stored until this task is triggered
83+
IVectorView<BluetoothLEAdvertisementReceivedEventArgs> advertisements = details.Advertisements();
84+
ss << L"EventCount: " << advertisements.Size() << L", ";
85+
86+
// The signal strength filter configuration of the trigger is returned such that further
87+
// processing can be performed here using these values if necessary. They are read-only here.
88+
auto rssiFilter = details.SignalStrengthFilter();
89+
ss << L"HighDBm: " << FormatOptionalInt16(rssiFilter.InRangeThresholdInDBm()) << L", ";
90+
ss << L"LowDBm: " << FormatOptionalInt16(rssiFilter.OutOfRangeThresholdInDBm()) << L", ";
91+
ss << L"Timeout (ms): " << FormatOptionalTimeSpanMs(rssiFilter.OutOfRangeTimeout()) << L", ";
92+
ss << L"Sampling (ms): " << FormatOptionalTimeSpanMs(rssiFilter.SamplingInterval());
93+
94+
DateTimeFormatter timestampFormatter(L"longtime");
95+
96+
// Advertisements can contain multiple events that were aggregated, each represented by
97+
// a BluetoothLEAdvertisementReceivedEventArgs object.
98+
for (auto const& advertisementEventArgs : advertisements)
99+
{
100+
ss << L"\n[" + timestampFormatter.Format(advertisementEventArgs.Timestamp()) + L"] ";
101+
ss << L"[" + to_hstring(advertisementEventArgs.AdvertisementType()) + L"]: ";
102+
ss << L"Rssi=" << advertisementEventArgs.RawSignalStrengthInDBm() << L"dBm";
103+
if (hstring name = advertisementEventArgs.Advertisement().LocalName(); !name.empty())
104+
{
105+
ss << L", localName=" << name;
106+
}
107+
// Check if there are any manufacturer-specific sections.
108+
// If there is, print the raw data of the first manufacturer section (if there are multiple).
109+
auto manufacturerData = advertisementEventArgs.Advertisement().ManufacturerData();
110+
if (manufacturerData.Size() > 0)
111+
{
112+
// Print the first one of the list
113+
ss << L", manufacturerData=[" << Utilities::FormatManufacturerData(manufacturerData.GetAt(0)) << L"]";
114+
}
115+
}
116+
117+
// Store the message in a local settings indexed by this task's name so that the foreground App
118+
// can display this message.
119+
ApplicationData::Current().LocalSettings().Values().Insert(taskInstance.Task().Name(), winrt::box_value(ss.str()));
120+
}
121+
122+
/// <summary>
123+
/// The entry point of a background task.
124+
/// </summary>
125+
/// <param name="taskInstance">The current background task instance.</param>
126+
void AdvertisementPublisherTask::Run(IBackgroundTaskInstance const& taskInstance)
127+
{
128+
publisherTaskInstance = taskInstance;
129+
130+
auto details = taskInstance.TriggerDetails().as<BluetoothLEAdvertisementPublisherTriggerDetails>();
131+
132+
// In this example, the background task simply constructs a message communicated
133+
// to the App. For more interesting applications, a notification can be sent from here instead.
134+
std::wostringstream ss;
135+
136+
// If the background publisher stopped unexpectedly, an error will be available here.
137+
BluetoothError error = details.Error();
138+
if (error != BluetoothError::Success)
139+
{
140+
ss << L"Error: " << to_hstring(error) << L", ";
141+
}
142+
143+
// The status of the publisher is useful to determine whether the advertisement payload is being serviced
144+
// It is possible for a publisher to stay in a Waiting state while radio resources are in use.
145+
BluetoothLEAdvertisementPublisherStatus status = details.Status();
146+
ss << L"Publisher status: " + to_hstring(status);
147+
148+
// Store the message in a local settings indexed by this task's name so that the foreground App
149+
// can display this message.
150+
ApplicationData::Current().LocalSettings().Values().Insert(taskInstance.Task().Name(), winrt::box_value(ss.str()));
151+
}
152+
}
153+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
6+
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
7+
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
8+
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
9+
//
10+
//*********************************************************
11+
12+
#pragma once
13+
14+
#include "AdvertisementWatcherTask.g.h"
15+
#include "AdvertisementPublisherTask.g.h"
16+
17+
namespace winrt::SDKTemplate::implementation
18+
{
19+
struct AdvertisementWatcherTask : AdvertisementWatcherTaskT<AdvertisementWatcherTask>
20+
{
21+
AdvertisementWatcherTask() = default;
22+
23+
void Run(Windows::ApplicationModel::Background::IBackgroundTaskInstance const& taskInstance);
24+
Windows::ApplicationModel::Background::IBackgroundTaskInstance watcherTaskInstance{ nullptr };
25+
};
26+
27+
struct AdvertisementPublisherTask : AdvertisementPublisherTaskT<AdvertisementPublisherTask>
28+
{
29+
AdvertisementPublisherTask() = default;
30+
31+
void Run(Windows::ApplicationModel::Background::IBackgroundTaskInstance const& taskInstance);
32+
Windows::ApplicationModel::Background::IBackgroundTaskInstance publisherTaskInstance{ nullptr };
33+
};
34+
}
35+
36+
namespace winrt::SDKTemplate::factory_implementation
37+
{
38+
struct AdvertisementWatcherTask : AdvertisementWatcherTaskT<AdvertisementWatcherTask, implementation::AdvertisementWatcherTask>
39+
{
40+
};
41+
42+
struct AdvertisementPublisherTask : AdvertisementPublisherTaskT<AdvertisementPublisherTask, implementation::AdvertisementPublisherTask>
43+
{
44+
};
45+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.35821.62
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BluetoothAdvertisement", "BluetoothAdvertisement.vcxproj", "{204F8E25-6B12-4466-B05B-33A48946881C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|ARM = Debug|ARM
11+
Debug|x64 = Debug|x64
12+
Debug|x86 = Debug|x86
13+
Release|ARM = Release|ARM
14+
Release|x64 = Release|x64
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{204F8E25-6B12-4466-B05B-33A48946881C}.Debug|ARM.ActiveCfg = Debug|ARM
19+
{204F8E25-6B12-4466-B05B-33A48946881C}.Debug|ARM.Build.0 = Debug|ARM
20+
{204F8E25-6B12-4466-B05B-33A48946881C}.Debug|ARM.Deploy.0 = Debug|ARM
21+
{204F8E25-6B12-4466-B05B-33A48946881C}.Debug|x64.ActiveCfg = Debug|x64
22+
{204F8E25-6B12-4466-B05B-33A48946881C}.Debug|x64.Build.0 = Debug|x64
23+
{204F8E25-6B12-4466-B05B-33A48946881C}.Debug|x64.Deploy.0 = Debug|x64
24+
{204F8E25-6B12-4466-B05B-33A48946881C}.Debug|x86.ActiveCfg = Debug|Win32
25+
{204F8E25-6B12-4466-B05B-33A48946881C}.Debug|x86.Build.0 = Debug|Win32
26+
{204F8E25-6B12-4466-B05B-33A48946881C}.Debug|x86.Deploy.0 = Debug|Win32
27+
{204F8E25-6B12-4466-B05B-33A48946881C}.Release|ARM.ActiveCfg = Release|ARM
28+
{204F8E25-6B12-4466-B05B-33A48946881C}.Release|ARM.Build.0 = Release|ARM
29+
{204F8E25-6B12-4466-B05B-33A48946881C}.Release|ARM.Deploy.0 = Release|ARM
30+
{204F8E25-6B12-4466-B05B-33A48946881C}.Release|x64.ActiveCfg = Release|x64
31+
{204F8E25-6B12-4466-B05B-33A48946881C}.Release|x64.Build.0 = Release|x64
32+
{204F8E25-6B12-4466-B05B-33A48946881C}.Release|x64.Deploy.0 = Release|x64
33+
{204F8E25-6B12-4466-B05B-33A48946881C}.Release|x86.ActiveCfg = Release|Win32
34+
{204F8E25-6B12-4466-B05B-33A48946881C}.Release|x86.Build.0 = Release|Win32
35+
{204F8E25-6B12-4466-B05B-33A48946881C}.Release|x86.Deploy.0 = Release|Win32
36+
EndGlobalSection
37+
GlobalSection(SolutionProperties) = preSolution
38+
HideSolutionNode = FALSE
39+
EndGlobalSection
40+
GlobalSection(ExtensibilityGlobals) = postSolution
41+
SolutionGuid = {B64FFD00-B813-4D60-886E-4BE135FA04CE}
42+
EndGlobalSection
43+
EndGlobal

0 commit comments

Comments
 (0)