Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting implementation of Bluetooth events
- Loading branch information
Showing
3 changed files
with
159 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
InTheHand.Net.Bluetooth/Platforms/Win32/RegisterDeviceNotificationSafeHandle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 32feet.NET - Personal Area Networking for .NET | ||
// | ||
// InTheHand.Net.Bluetooth.Win32.RegisterDeviceNotificationSafeHandle | ||
// | ||
// Copyright (c) 2008-2021 In The Hand Ltd, All rights reserved. | ||
// Copyright (c) 2008-2011 Alan J.McFarlane, All rights reserved. | ||
// This source code is licensed under the MIT License | ||
|
||
using Microsoft.Win32.SafeHandles; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace InTheHand.Net.Bluetooth.Win32 | ||
{ | ||
internal sealed class RegisterDeviceNotificationSafeHandle : SafeHandleZeroOrMinusOneIsInvalid | ||
{ | ||
public RegisterDeviceNotificationSafeHandle() : base(true) // ownsHandle | ||
{ | ||
} | ||
|
||
protected override bool ReleaseHandle() | ||
{ | ||
return BluetoothUnregisterDeviceNotification(handle); | ||
} | ||
|
||
private static bool BluetoothUnregisterDeviceNotification(IntPtr deviceNotificationHandle) | ||
{ | ||
System.Diagnostics.Debug.Assert(deviceNotificationHandle != IntPtr.Zero, "Device notification not registered."); | ||
bool success = UnregisterDeviceNotification(deviceNotificationHandle); | ||
System.Diagnostics.Debug.Assert(success, "UnregisterDeviceNotification success false."); | ||
return success; | ||
} | ||
|
||
[DllImport("user32", ExactSpelling = true, SetLastError = true)] | ||
[return: MarshalAs(UnmanagedType.Bool)] | ||
private static extern bool UnregisterDeviceNotification(IntPtr handle); | ||
} | ||
} |