Click here to Skip to main content
12,696,920 members (28,901 online)
Click here to Skip to main content
Add your own
alternative version


50 bookmarked

Serial Port Enumeration on Windows Mobile

, 28 Nov 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
How to enumerate serial ports in a Windows Mobile device (including the virtual ports created by the Microsoft Bluetooth stack).

Screenshot - WMEnumComPorts.png


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 Software\Microsoft\Bluetooth\Serial\Ports key.

Using the code

Using the serial port enumeration code is quite simple. Start by declaring an object of type CSerialPortEnum:

CSerialPortEnum portEnum;

Now, we are ready to enumerate the serial ports:

size_t i;
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 EnumeratePorts function.

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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

João Paulo Figueira
Software Developer (Senior) Frotcom International
Portugal Portugal
I work on R&D for Frotcom International, a company that develops web-based fleet management solutions.

You may also be interested in...


Comments and Discussions

GeneralBluetooth virtual serial por Pin
xiaboyang31-Mar-11 21:30
memberxiaboyang31-Mar-11 21:30 
GeneralFinding GPS device Pin
werner.keilholz13-Feb-09 12:29
memberwerner.keilholz13-Feb-09 12:29 
GeneralRe: Finding GPS device Pin
Joao Paulo Figueira13-Feb-09 12:56
memberJoao Paulo Figueira13-Feb-09 12:56 
GeneralRe: Finding GPS device Pin
werner.keilholz13-Feb-09 13:27
memberwerner.keilholz13-Feb-09 13:27 
GeneralRe: Finding GPS device Pin
Joao Paulo Figueira14-Feb-09 2:12
memberJoao Paulo Figueira14-Feb-09 2:12 
GeneralRe: Finding GPS device Pin
werner.keilholz15-Feb-09 6:24
memberwerner.keilholz15-Feb-09 6:24 
QuestionGetting Audio Stream from Phone coonected via USB or Blue Tooth Pin
pankaj motiyar15-Jul-08 20:50
memberpankaj motiyar15-Jul-08 20:50 
GeneralHello sir Pin
TheLibra17-May-08 21:33
memberTheLibra17-May-08 21:33 
GeneralProblem with enumeration Pin
susilrani13-May-08 23:39
membersusilrani13-May-08 23:39 
GeneralRe: Problem with enumeration Pin
Joao Paulo Figueira14-May-08 0:00
memberJoao Paulo Figueira14-May-08 0:00 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170118.1 | Last Updated 29 Nov 2007
Article Copyright 2007 by João Paulo Figueira
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid