Introduction
This article discusses how Windows Mobile 5.0 devices can connect through the bluetooth using InTheHand
DLL in C#.
Setting Bluetooth Discoverable in Windows Mobile
We need to set our mobile as bluetooth discoverable. In Bluetooth settings, you will check the discoverable option.
InTheHand
In Compact framework 1.0, we don't have any managed class which handles bluetooth socket connections. InTheHand
is a third party component which gives the functionalities of bluetooth services for windows mobile. You can download InTheHand
from here.
Using the Code
The source code is available for download from the link at the top of this article. The devices are displayed in a combobox when we click the first button name of Search devices. Then we can connect the selected device from the combobox by clicking the button named Connect.
The code is noted below which is used in the project.
using InTheHand.Net;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
private BluetoothClient bluetoothClient;
private Guid service = BluetoothService.DialupNetworking;
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
bluetoothClient = new BluetoothClient();
Cursor.Current = Cursors.WaitCursor;
BluetoothDeviceInfo[] bluetoothDeviceInfo = { };
bluetoothDeviceInfo = bluetoothClient.DiscoverDevices(10);
comboBox1.DataSource = bluetoothDeviceInfo;
comboBox1.DisplayMember = "DeviceName";
comboBox1.ValueMember = "DeviceAddress";
comboBox1.Focus();
Cursor.Current = Cursors.Default;
bluetoothClient.Connect(new BluetoothEndPoint
((BluetoothAddress)comboBox1.SelectedValue, service));
Conclusion
This will be helpful for working in Windows mobile using C#. Hereafter, we can do something via bluetooth with two Windows mobile devices.