Click here to Skip to main content
13,195,821 members (55,625 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 10 Dec 2005

Enumerating Serial Ports On Pocket PC

, 10 Dec 2005
Rate this:
Please Sign up or sign in to vote.
C++ Class to enumerate COM ports on Pocket PC
Sample Image - COMEnum.gif


Getting information about available ports on Pocket PC device is troublesome due to the fact that Pocket PC registry is different from the ones found in PC operating systems. Information on how to do it in Pocket PC is scarce and quite often does not work. For instance, code posted here recommends to detect IrDA port by looking it up in "HKEY_LOCAL_MACHINE\\Comm\\IrDA" which does not work on Pocket PC 2002 and Pocket PC 2003.

This article introduces CCOMEnum class as an attempt to overcome these issues.


CCOMEnum class finds all available COM ports by parsing "HKEY_LOCAL_MACHINE\\Drivers\\Active" content. All found ports and related data are stored in the structure. Class offers an option of qualifying found ports by obtaining a handle. Qualifying will reduce the number of found ports. Why not do qualifying always? One example - USB port. It is a slave on Pocket PC. Therefore it will not show up when qualify is enabled.

Using the Code

COM Port enumeration is done by calling EnumerateCOMs() function:

virtual void EnumerateCOMs(BOOL Verify);

Verify parameter will control whether or not to verify port by obtaining a handle to it. Once EnumerateCOMs() is called, other member functions can be used to view the data. GetTotalComs() will return number of ports found. This number can be used in for loops or if statements when reading data from CCOMEnum class:

#include "CCOMEnum.h"

CCOMEnum    Enumerator;
UINT        i;
CString    portName;
CString    portKey;
int        portIndex;


i = 2;

for(i=0; i < Enumerator.GetTotalComs(); i++)
    if(Enumerator.GetPortSimpleKey(i) == "Serial2")
        portName     = Enumerator.GetPortName(i);    // "COM2:"
        portKey        = Enumerator.GetPortKey(i);    // 
        portIndex    = Enumerator.GetPortIndex(i);    // Such as 2

GetPortSimpleKey() and GetPortKey() return CString value that can be used to sort ports out by functionality.


The current version is 1.0. Although this code will be periodically updated here, for the latest code please check developer's web site There, you can also download a pre-built executable.


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


About the Author

Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralAnother way Pin
AndrewAZ5-Dec-06 22:33
memberAndrewAZ5-Dec-06 22:33 
QuestionRe: Another way Pin
markusschroth3-Jan-07 9:26
membermarkusschroth3-Jan-07 9:26 
AnswerRe: Another way [modified] Pin
AndrewAZ8-Jan-07 22:22
memberAndrewAZ8-Jan-07 22:22 
QuestionUsage of CString::Format Pin
MechJayTi19-Sep-06 0:02
memberMechJayTi19-Sep-06 0:02 
QuestionAnother possibility Pin
Tony Kmoch12-Dec-05 23:30
memberTony Kmoch12-Dec-05 23:30 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171019.1 | Last Updated 10 Dec 2005
Article Copyright 2005 by advatronix
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid