In The Hand - .NET Components for Mobility
BluetoothWin32Authentication Class
NamespacesInTheHand.Net.BluetoothBluetoothWin32Authentication
Provides Bluetooth authentication services on desktop Windows.
Declaration Syntax
C#Visual Basic
public class BluetoothWin32Authentication : IDisposable
Public Class BluetoothWin32Authentication _
	Implements IDisposable
Members
All MembersConstructorsMethodsFields



IconMemberDescription
BluetoothWin32Authentication(BluetoothAddress, String)
Initializes a new instance of the BluetoothWin32Authentication class, to respond to a specific address with a specific PIN string.

BluetoothWin32Authentication(EventHandler<(Of <(BluetoothWin32AuthenticationEventArgs>)>))
Initializes a new instance of the BluetoothWin32Authentication class, to call a specified handler when any device requires authentication.

Dispose()()()
Release the unmanaged resources used by the BluetoothWin32Authentication.

Dispose(Boolean)
Release the unmanaged resources used by the BluetoothWin32Authentication, and optionally disposes of the managed resources.

Equals(Object)
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Finalize()()()
Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.
(Inherited from Object.)
GetHashCode()()()
Serves as a hash function for a particular type. GetHashCode()()() is suitable for use in hashing algorithms and data structures like a hash table.
(Inherited from Object.)
GetType()()()
Gets the Type of the current instance.
(Inherited from Object.)
MemberwiseClone()()()
Creates a shallow copy of the current Object.
(Inherited from Object.)
NativeErrorDeviceNotConnected
Windows’ ERROR_DEVICE_NOT_CONNECTED

NativeErrorNotAuthenticated
Windows’ ERROR_NOT_AUTHENTICATED

NativeErrorSuccess
Windows’ ERROR_SUCCESS

ToString()()()
Returns a String that represents the current Object.
(Inherited from Object.)
Remarks

Respond to requests for authentication for Bluetooth devices. It is used by BluetoothClient to support its Pin property, in that case an instance is created specifying the device that is being connected to and the PIN string to use. It can also be used a mode where a user supplied callback will be called when any device requires authentication, see the example below.

The instance will continue receiving authentication requests until it is disposed or garbage collected, so keep a reference to it whilst it should be active and call Dispose()()() when you’re finished.

Examples
If one wants to respond to PIN requests for one device with a known PIN then use the simple form which is initialized with an address and PIN.
CopyC#
BluetoothWin32Authentication authenticator
    = new BluetoothWin32Authentication(remoteEP.Address, m_pin);
// when the peer is expected to require pairing, perhaps do some work.
authenticator.Dispose();
If one wants to see the PIN request, perhaps to be able to check the type of the peer by its address then use the form here which requests callbacks.
Copy 
Using pairer As New BluetoothWin32Authentication(AddressOf Win32AuthCallbackHandler)
    Console.WriteLine("Hit Return to stop authenticating")
    Console.ReadLine()
End Using
...

Sub Win32AuthCallbackHandler(ByVal sender As Object, ByVal e As InTheHand.Net.Bluetooth.BluetoothWin32AuthentionEventArgs)
   Dim address As String = e.Device.DeviceAddress.ToString()
   Console.WriteLine("Received an authentication request from address " + address)

   ' compare the first 8 hex numbers, this is just a special case because in the
   ' used scenario the model of the devices can be identified by the first 8 hex
   ' numbers, the last 4 numbers being the device specific part.
   If address.Substring(0, 8).Equals("0099880D") OrElse _
           address.Substring(0, 8).Equals("0099880E") Then
       ' send authentication response
       e.Pin = "5276"
   ElseIf (address.Substring(0, 8).Equals("00997788")) Then
       ' send authentication response
       e.Pin = "ásdfghjkl"
   End If
End Sub
Inheritance Hierarchy
Object
BluetoothWin32Authentication

Assembly: InTheHand.Net.Personal (Module: InTheHand.Net.Personal) Version: 2.2.0.0