Change Device Assigned to Outbound COM Port

With the Microsoft Bluetooth stack a single outbound virtual COM port is supported, to set this up you have to bond with the device. If you want to switch between several devices at different times this is awkward. You can however alter the registry settings between connections to switch devices.

1. Setup an Outbound COM port for the first device

2. Bond with the other device(s) you wish to use

3. Make a note of the bluetooth IDs of these bonded devices – see the subkeys of [HKEY_LOCAL_MACHINESOFTWAREMicrosoftBluetoothDevice] for details

4. Before switching devices ensure you do not have the outbound virtual COM port opened (often COM 5 but check on your device).

5. Replace the value of “OBBDaddr” in the key [HKEY_LOCAL_MACHINESOFTWAREMicrosoftBluetoothSerialPort] with the bluetooth address of your required device.

6. Open the COM port – now connects to the device specified in the above registry key.


Bluetooth Comparison

Now that the dust has settled on MEDC, I’m thinking about how to move forward with the Bluetooth library. I had essentially put development on hold when I first heard that Microsoft were preparing their own source package prior to MEDC. When it was released, I was a little disappointed in their functionality (and compatibility) so I’ve decided to press on improving the Bluetooth.NET library. It’s going to take a few weeks to put together the next version, one key aim is to synchronise the source, samples, documentation and binaries with this next release, some of the previous releases have been binary only.

In the meantime here is a comparison of the functionality available today in the widely available Bluetooth libraries/SDKs:-

  Managed libraries Native code SDKs
  Bluetooth.NET Microsoft Windows Embedded Source Tools for Bluetooth Technology High-Point BTAccess Microsoft Windows CE SDK Broadcom SDK
Bluetooth Functionality  
Toggle Radio * *   *  
Device Discovery *   * * *
Service Discovery     * * *
Client Sockets * * * * *
Server Sockets * * * * *
COM Port mapping *   * * *
Bluetooth Stacks  
Microsoft Stack * *   *  
Broadcom Stack     *   *
.NET v1 *      
.NET v2 *    
.NETCF v1 *   *
.NETCF v2 * *  
Pocket PC 2002     *   *
Windows CE.NET 4.2 *     *  
Windows Mobile 2003 *   * * *
Windows CE 5.0 * *   *  
Windows Mobile 5.0 * *   *  
Windows XP (SP1 and above) *     *
Package features  
Help documentation *   * * *
Source code * *      
Sample projects *     *  
Price FREE FREE $750 FREE $1,395

Obviously your feedback will help shape the library, so what are the key features you’d like to see added or improved?


Bluetooth Library (March Edition)

To facilitate using the library in Visual Studio 2005 Betas I have made a few minor updates to the managed Bluetooth library, new/fixed in this release:-

  • Now works under .NETCF 1.0, .NETCF 2.0, .NET 1.1 .NET 2.0 (Not tested under the .NET 1.0 desktop framework but should work).
  • On Windows CE remote name lookups are performed “on-demand” rather than during device discovery to reduce discovery time.
  • Reintroduced the BluetoothSocket helper class which provides a shortcut to create a Socket for working with Bluetooth independently of the existing BluetoothClient / BluetoothListener classes.
  • Removed OpenNETCF.dll dependency, cures deployment problems on desktop machines.

Download the latest version here:-



Bluetooth Desktop Code NETCF

Bluetooth Remote Control

Mike Hall posted a link on his blog to a channel9 interview with Anil Dhawan from the Windows Mobile team discussing Bluetooth programming, which I recommend you check out. Anil gave a demo of a native code application to remote control PowerPoint on a desktop PC. This inspired me to put some finishing touches to a test application I built for the Bluetooth .NETCF library – It is by no means finished but it works (with the wind blowing in the right direction!).

There are two components, on the Smartphone an application which you first select Search from the menu and it will do a lookup of local discoverable devices, then select one and select the Connect menu option. Once connected any d-pad or number keys are captured and sent over bluetooth. As I said it was an unfinished project, key items missing are:-

  • Store desktop address in the registry so we only have to search once

  • More intuitive interface 🙂

  • Support for key mapping – map the device keys to application specific commands e.g. for media player etc

On the desktop a simple listener which listens on a custom service, incoming data is received as keycodes which are broadcast on the system using the SendKeys.Send method.

On an unrelated note, thanks to Sergey Bogdanov who has contributed an implementation of the SendKeys class to be included in the upcoming SDF v1.3 release.

With the listener application running and the Smartphone client connected you can automate (within reason) whatever app has the focus. It works great for Powerpoint browsing between slides using the d-pad on the phone. The usual disclaimer applies – this works only with the Microsoft Bluetooth stack on both device and desktop, I tested with an Orange SPV C500.

The two projects are available to download here.

Bluetooth NETCF

Bluetooth Library (February Edition)

Not a huge amount of change since last months release but I just wanted to post the latest update. The download includes the same Chat application samples along with the complete solution for the library itself.


The main changes in this release are:-

  • BluetoothRadio class which handles the radio state on a single or multiple radio device. Multiple radios are only supported on XP, Windows CE supports a single radio device.
  • BluetoothSecurity class which has a couple of methods to automate the pairing (bonding) process between devices. Using SetPin and RevokePin you can specify the PIN to use with a particular remote device. Using PairRequest you can force the device to intiate a connection and bond with the remote device with the specified PIN code. Currently the BluetoothSecurity class is built for Windows CE only, in a future update this functionality will be extended to run on the desktop too.
  • General housekeeping – P/Invokes have been moved into a single NativeMethods class and a few new ones added, though not all are used by the library yet.

Online documentation for this build can be browsed here.


Visually identify your Bluetooth stack

Since it’s such a frequently asked question I’ve documented it here with some images which should hopefully clear up any confusion. The following screenshots show how to identify the Bluetooth stack on your Pocket Pc without writing any code or delving into the registry or system files.



Bluetooth Off

Microsoft Stack (Disabled)

Widcomm Stack (Disabled)

Bluetooth On

Microsoft Stack (Enabled)

Widcomm Stack (Enabled)

Settings (Click Icon)

Microsoft Stack Settings

Pocket PC 2003 Second Edition

Microsoft Stack Settings Second Edition

Widcomm Stack Menu


Finally a quick reminder, the Bluetooth.NET library only works currently with the Microsoft stack, so if you have Widcomm/Broadcom or any other you’ll have to look at third-party APIs.

Bluetooth NETCF

Bluetooth Build 50115

I’ve posted an updated build of the Bluetooth library here. It adds full support for the desktop, improved class-of-device and other properties.

The sample app is now supplied in Pocket Pc, Smartphone and Desktop versions which all talk to each other.

Bluetooth NETCF

Rudolph the Bluetoothed Reindeer

I’ve uploaded a new release of the Bluetooth library which adds the key feature of hosting services over bluetooth. This now allows two-way communications between devices and to demonstrate how this works I’ve included a sample Bluetooth Chat application. This registers a custom bluetooth profile and listens for incoming connections, and creates outgoing connections using this service identifier to other devices. In this way it only communicates with other devices exposing this service and wont interfere with any other applications using Bluetooth.

Thanks go out to Wei-Meng Lee for giving permission to base the sample on his previous IrDA chat application available with this MSDN article. The Bluetooth version works in a very similar way, with the exception of doing a device discovery when it first loads. An enhancement yet to be added is the ability to periodically discover in a background thread. From the app screen select the target device which must also be running the software and Bluetooth must be Discoverable. Then type your message and click send and it will appear onscreen on the other device. In the below example I had a brief conversation with Santa who was half-way up a chimney at the time – such is the versatility of Bluetooth 🙂

Bluetooth Chat

The ZIP file below includes the Bluetooth library project and compiled output, and the BTChat sample project. As I get time to do more work on the library I’ll post some other examples, and include versions for other platforms e.g. Smartphone and XP.

Known issues:-

  • Hosting services doesn’t yet work on XP (some of the structures are slightly different so this requires a little more work)
  • BluetoothClient.RemoteDeviceName doesn’t work so you can’t retrieve the device name from an open connection (Device names work correctly during discovery on both Windows CE and XP)
  • BluetoothSerialPort (For emulating a COM port) is not fully tested and probably doesn’t work – SerialPortProfile connections work great using sockets (BluetoothClient).


  • SDF v1.2
  • Windows CE Device or Windows XP computer using the Microsoft Bluetooth stack (Sorry but Widcomm is not supported).




If you have any comments or questions please drop me an email. For now all that remains is for me to wish you a Very Merry Christmas!

Bluetooth NETCF

Online Bluetooth code updated

There were some recent enquries on the OpenNETCF Forums about the current Bluetooth code. It seems I had refreshed the website with some development code which would only work if a couple of items were commented out. This is because these classes (Sdp related) are still under development and require COM interop and are currently built against InTheHand.Interop.dll which does COM interop with no native DLL required, and is used in my PocketOutlook and ADOCE products.

So I’ve updated the code online and attached a .zip of the project below which will build successfully against the v1.2 SDF (and the compiled dll is included in the bin folder). Documentation is in the online library at

I’m working on a sample application to accompany the library, but it’s been tested with a Bluetooth GPS unit and a Jabra headset successfully (Before you ask it only uses the control functionality of the headset, not the audio stream). But you can programmatically make the headset ring and capture the event when the user presses the answer button. Not terribly exciting but an interesting start, I guess I need some more unusual Bluetooth devices to test against.

What isn’t working in this release is the ability to host a service and allow other devices to discover it, since this requires some of the ongoing Sdp work. Once this is in place you will be able to do data transfer between devices which is when the fun will really begin!

Also bear in mind this is designed to work only with devices with the Microsoft Bluetooth stack, for example HTC Phone Edition devices and most Smartphone 2003 models.


Bluetooth NETCF

Toggle Bluetooth on an iPaq device

We can already enable and disable Bluetooth on devices equipped with Microsoft’s Bluetooth stack. In the case of iPaq devices, which use the Widcomm stack, it is possible to toggle the radio state using an API provided in HP’s iPAQUtil.dll. This can be P/Invoked from a .NETCF project like so:-

[DllImport(“iPAQUtil.dll”, SetLastError=true)]

public static extern bool iPAQSetBlueToothRadio(ref int lpdwValue);

Which you can then call with:-

int val = 0;

iPAQSetBlueToothRadio(ref val);

Where val is either 0 to disable Bluetooth, or 1 to enable it. Tested on an iPaq 2210 but should work on any other iPaq device with Bluetooth.


The following should also work for devices with WiFi built in:-

[DllImport(“iPAQUtil.dll”, SetLastError=true)]

public static extern bool iPAQSetWLANRadio(ref int lpdwValue);

But I’ve not been able to test this myself.