65.9K
CodeProject is changing. Read more.
Home

Bluetooth Connection in Windows Mobile 5.0 using InThehand - C#

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.91/5 (6 votes)

Jun 28, 2007

CPOL
viewsIcon

118063

downloadIcon

4108

Bluetooth connection in Windows Mobile 5.0

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.

//
// Directives.
//
using InTheHand.Net;
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
//
//Declaration
//
private BluetoothClient bluetoothClient;
private Guid service = BluetoothService.DialupNetworking; 
//
//Search the devices and displaying in combobox.
//
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;
//
//Connect the selected device.
//
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.