This short article describes a serial port enumeration method for Windows Mobile devices that includes the Microsoft Bluetooth stack virtual COM ports.
I was recently asked to write a little user interface that would enumerate all COM ports on Windows Mobile devices and that, if possible, provided a brief description of the attached device. After looking around CodeProject for a solution, I found a very promising approach in Joaquín's article. I followed a similar approach by enumerating all the keys under
HKEY_LOCAL_MACHINE\Drivers\Active but found a big problem: on devices with the Microsoft Bluetooth stack, the virtual COM ports are not listed under this key. Interestingly, the Widcomm Bluetooth stack does seem to get this right.
The image above shows two Windows Mobile devices running the sample application. On the right, you see a screen capture of a WM6 Asus P535 with the Widcomm Bluetooth stack. All the enumerated ports were drawn from the active drivers registry key as I stated above. On the left, you see a WM5 i-mate K-Jam device with the Microsoft Bluetooth stack. In order to retrieve the information about the
COM6: port, I had to look elsewhere in the registry, namely under the
Using the code
Using the serial port enumeration code is quite simple. Start by declaring an object of type
Now, we are ready to enumerate the serial ports:
int iItem = 0;
for(i = 0; i < portEnum.GetCount(); ++i)
const CSerialPortInfo *pInfo = portEnum[i];
if(pInfo != NULL)
iItem = listPort.AddItem(iItem, 0, pInfo->GetPortName());
listPort.SetItemText(iItem, 1, pInfo->GetDescription());
Please note that the enumeration object does not sort the list by COM port number. If you need to reuse the object to enumerate the serial ports again, just call the
Also note that this code has only been tested on Windows Mobile 5 and 6 devices (Pocket PC).
- 2007-11-29 - First publication on CodeProject.