Click here to Skip to main content
15,881,882 members
Articles / Mobile Apps

Bluetooth Connection in Windows Mobile 5.0 using InThehand - C#

Rate me:
Please Sign up or sign in to vote.
2.91/5 (6 votes)
28 Jun 2007CPOL 116.1K   4.1K   48   14
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.

C#
//
// 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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
Hi Viewers,

I wish to all. This is Vinoth. This is where I try to condense everything that you need to know about me.

Blog:

visit my blog

Interests:

I'm passionate about a great many things and continually learning about the things that interest me. They are wearable computers, User Interface Design, Artificial life, Industrial music.

Comments and Discussions

 
Questionclarification Pin
Member 114193722-Feb-15 0:06
Member 114193722-Feb-15 0:06 
Questionreceiving data from a sensors Pin
BlueRockDevil6-May-13 0:19
BlueRockDevil6-May-13 0:19 
SuggestionWhy NullReferenceException? Pin
WLRoger30-Nov-12 12:55
WLRoger30-Nov-12 12:55 
QuestionWhy NullReferenceException? Pin
roby58211-Sep-09 0:15
roby58211-Sep-09 0:15 
AnswerRe: Why NullReferenceException? Pin
Gus Arik13-Sep-09 19:20
Gus Arik13-Sep-09 19:20 
me too have found that error..

how to fixed it??
QuestionHow to send a file after connecting Pin
windvp29-May-09 0:07
windvp29-May-09 0:07 
AnswerRe: How to send a file after connecting Pin
S.Vinothkumar29-May-09 19:57
S.Vinothkumar29-May-09 19:57 
GeneralRe: How to send a file after connecting Pin
fardins20-Dec-10 22:56
fardins20-Dec-10 22:56 
GeneralBluetooth Detection and Data ransfer Pin
Pradip P Thakare5-May-09 0:05
Pradip P Thakare5-May-09 0:05 
GeneralTransmitting Text Message to another Bluetooth Device Pin
mahmoud ankeer14-Apr-09 22:14
mahmoud ankeer14-Apr-09 22:14 
GeneralCode in C# for data transfer between mobile and pc Pin
MalvikaBahl26-Jan-09 19:46
MalvikaBahl26-Jan-09 19:46 
GeneralTo send some text to bluetooth printer for printing using InThehand dll Pin
Awaneesh Pandey24-Oct-07 22:42
Awaneesh Pandey24-Oct-07 22:42 
QuestionAn error occur Pin
ChunrenHu9-Oct-07 0:19
ChunrenHu9-Oct-07 0:19 
AnswerRe: An error occur Pin
desenfoque21-Apr-10 8:48
desenfoque21-Apr-10 8:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.