-
Notifications
You must be signed in to change notification settings - Fork 531
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
How to use BluetoothLEAdvertisement::SetFlags API #2310
Comments
Can you share a minimal repro? Sorry, I'm not familiar with this API. Generally, when an API expects a |
Would it end up looking something like in Rust then? I still get
|
Yes, when the code gen changes are done you can just use |
Gotcha, thanks! How would I go about providing an |
As I said, this should all be automatic but for the moment here's what you'll have to do to implement
use windows::{core::*, Devices::Bluetooth::Advertisement::*, Foundation::*};
fn main() -> Result<()> {
let blue = BluetoothLEAdvertisement::new()?;
// Clear flags
blue.SetFlags(None)?;
// Read cleared flags
assert!(blue.Flags().unwrap_err().code().is_ok());
// Set boxed flags
blue.SetFlags(&Reference::box_value(
BluetoothLEAdvertisementFlags::LimitedDiscoverableMode,
))?;
// Read unboxed flags
assert!(blue.Flags()?.Value()? == BluetoothLEAdvertisementFlags::LimitedDiscoverableMode);
Ok(())
}
#[implement(IReference<T>)]
struct Reference<T>(T)
where
T: RuntimeType;
impl<T: RuntimeType> Reference<T> {
fn box_value(value: T) -> IReference<T> {
Self(value).into()
}
}
impl<T: RuntimeType + 'static> IReference_Impl<T> for Reference<T> {
fn Value(&self) -> Result<T> {
Ok(self.0.clone())
}
}
impl<T: RuntimeType + 'static> IPropertyValue_Impl for Reference<T> {
fn Type(&self) -> Result<PropertyType> {
todo!()
}
fn IsNumericScalar(&self) -> Result<bool> {
todo!()
}
fn GetUInt8(&self) -> Result<u8> {
todo!()
}
fn GetRect(&self) -> Result<Rect> {
todo!()
}
fn GetUInt8Array(&self, _: &mut Array<u8>) -> Result<()> {
todo!()
}
fn GetInt16Array(&self, _: &mut Array<i16>) -> Result<()> {
todo!()
}
fn GetUInt16Array(&self, _: &mut Array<u16>) -> Result<()> {
todo!()
}
fn GetInt32Array(&self, _: &mut Array<i32>) -> Result<()> {
todo!()
}
fn GetUInt32Array(&self, _: &mut Array<u32>) -> Result<()> {
todo!()
}
fn GetInt64Array(&self, _: &mut Array<i64>) -> Result<()> {
todo!()
}
fn GetUInt64Array(&self, _: &mut Array<u64>) -> Result<()> {
todo!()
}
fn GetSingleArray(&self, _: &mut Array<f32>) -> Result<()> {
todo!()
}
fn GetDoubleArray(&self, _: &mut Array<f64>) -> Result<()> {
todo!()
}
fn GetChar16Array(&self, _: &mut Array<u16>) -> Result<()> {
todo!()
}
fn GetBooleanArray(&self, _: &mut Array<bool>) -> Result<()> {
todo!()
}
fn GetStringArray(&self, _: &mut Array<HSTRING>) -> Result<()> {
todo!()
}
fn GetInspectableArray(&self, _: &mut Array<IInspectable>) -> Result<()> {
todo!()
}
fn GetGuidArray(&self, _: &mut Array<GUID>) -> Result<()> {
todo!()
}
fn GetDateTimeArray(&self, _: &mut Array<DateTime>) -> Result<()> {
todo!()
}
fn GetTimeSpanArray(&self, _: &mut Array<TimeSpan>) -> Result<()> {
todo!()
}
fn GetPointArray(&self, _: &mut Array<Point>) -> Result<()> {
todo!()
}
fn GetSizeArray(&self, _: &mut Array<Size>) -> Result<()> {
todo!()
}
fn GetRectArray(&self, _: &mut Array<Rect>) -> Result<()> {
todo!()
}
fn GetInt16(&self) -> Result<i16> {
todo!()
}
fn GetUInt16(&self) -> Result<u16> {
todo!()
}
fn GetInt32(&self) -> Result<i32> {
todo!()
}
fn GetUInt32(&self) -> Result<u32> {
todo!()
}
fn GetInt64(&self) -> Result<i64> {
todo!()
}
fn GetUInt64(&self) -> Result<u64> {
todo!()
}
fn GetSingle(&self) -> Result<f32> {
todo!()
}
fn GetDouble(&self) -> Result<f64> {
todo!()
}
fn GetChar16(&self) -> Result<u16> {
todo!()
}
fn GetBoolean(&self) -> Result<bool> {
todo!()
}
fn GetString(&self) -> Result<HSTRING> {
todo!()
}
fn GetGuid(&self) -> Result<GUID> {
todo!()
}
fn GetDateTime(&self) -> Result<DateTime> {
todo!()
}
fn GetTimeSpan(&self) -> Result<TimeSpan> {
todo!()
}
fn GetPoint(&self) -> Result<Point> {
todo!()
}
fn GetSize(&self) -> Result<Size> {
todo!()
}
} |
Awesome, thank you so much! Will close this issue as #292 seems to be the main issue. |
Reopening as use of this API results in
main.rs:
|
Same issue with the SetLocalName API
|
edit: Just checked the docs and it seems it's a system-reserved API so should maybe be removed instead. |
The minimal, reproducible example I provided #2310 (comment) works without error, at least on my machine. If you think you've found an issue with windows-rs then please provide a minimal, reproducible example. Otherwise, if you have questions about how to use the API you're better off heading over to https://stackoverflow.com/ as I don't have any particular insights on how this API is meant to work in practice. |
Gotcha, the problem is still reproducible, I just added
so it looks like:
to your code snippet above and it errors out with |
Hi @anayw2001, not seeing any issues here either. This is very likely related to your Bluetooth software or hardware stack--try updating your drivers perhaps. We can't help with Bluetooth issues here. I recommend posting on Microsoft Q&A--there are engineers that answer questions there. Specifically, the UWP area/tag seems apt. (https://learn.microsoft.com/en-us/answers/tags/105/windows-uwp) Collecting Bluetooth logs may help you gain additional insights too (https://github.com/Microsoft/busiotools/tree/master/bluetooth/tracing). Closing as this is unrelated to the Rust crate. |
Hi,
I've been trying to figure out how to use the SetFlags API for creating a General Discoverability BluetoothLEAdvertisement, but I cannot figure out how to correctly type the parameter so the conversions are completed automatically.
I have tried:
BluetoothLEAdvertisementFlags::GeneralDiscoverabilityMode()
&BluetoothLEAdvertisementFlags::GeneralDiscoverabilityMode().into()
(&BluetoothLEAdvertisementFlags::GeneralDiscoverabilityMode()).into()
Would be much appreciated if I could receive some guidance on how to create the required InParam<IReference> type.
The text was updated successfully, but these errors were encountered: