Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Bluetooth Connection in Windows Mobile 5.0 using InThehand - C#

0.00/5 (No votes)
28 Jun 2007 1  
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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here