Click here to Skip to main content
12,818,688 members (28,532 online)
Click here to Skip to main content
Add your own
alternative version


41 bookmarked
Posted 3 Mar 2000

EnumSerialPorts v1.02 - Enumerating Serial Ports

, 3 Mar 2000
Rate this:
Please Sign up or sign in to vote.
A freeware MFC function to enumerate serial ports.
  • Download source files - 7 Kb
  • Introduction

    Welcome to EnumSerialPorts v1.01, a simple MFC function to enumerate the serial ports installed on your machine.

    API Reference
    Contacting the Author


    • Simple C style function interface.
    • The code works on both Windows 95/98 and NT.
    • The code is fully Unicode compliant and include Unicode built options in the workspace file.


    • To use the function in your code simply #include "enumser.cpp" in your project and #include "enumser.h" in which ever of your modules needs to make calls to the function.
    • Your code will need to include MFC either statically or dynamically.
    • To see the class in action, have a look at the main function in the module main.cpp.


    v1.0 (3 November 1998)
    • Initial Public release.

    v1.01 (23 February 1999)

    • Code now uses QueryDosDevice() if running on NT to determine which serial ports are available. This avoids having to open the ports at all. It should operate a lot faster in addition.

    V1.02 (12 December 1999)

    • Fixed a problem in the Win9x code path when trying to detect deactivated IRDA-ports. When trying to open those, you will get the error-code ERROR_GEN_FAILURE.

    API Reference


    void ::EnumerateSerialPorts(CUIntArray& ports);


    • ports -- Upon return this array will contain the port numbers of all the serial ports installed on the computer.

    Contacting the Author

    PJ Naughter
    12 December 1999


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    PJ Naughter
    United States United States
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    GeneralUintArray Pin
    drequinox4-Sep-06 11:44
    memberdrequinox4-Sep-06 11:44 
    GeneralProblem: Other devices starting with "Com"... Pin
    Supermagle11-Nov-05 4:03
    memberSupermagle11-Nov-05 4:03 
    GeneralRe: Problem: Other devices starting with "Com"... Pin
    Supermagle11-Nov-05 4:12
    memberSupermagle11-Nov-05 4:12 
    Joseph126-May-03 9:53
    memberJoseph126-May-03 9:53 
    JLT7623-Feb-05 17:28
    memberJLT7623-Feb-05 17:28 
    GeneralSuggestion for another method Pin
    chris10919-Mar-02 4:03
    memberchris10919-Mar-02 4:03 
    GeneralThe way I do it ... Pin
    anonymous24-Aug-01 8:36
    memberanonymous24-Aug-01 8:36 
    GeneralIncorrect COM0 detection Pin
    Anonymous6-Aug-01 21:26
    memberAnonymous6-Aug-01 21:26 
    I'm using WinNT4. I get two COM0 when I use your library. After debugging, I find that there are devices named comxxxx where xxxx is anything (eg comDet). In this case, the _ttoi will return 0 because it failed to translate 'det' to a number.

    In other words, even if the first three characters are com, it may not be a com port. You have to verify that the trailing characters are all numbers.
    GeneralRe: Incorrect COM0 detection Pin
    Anonymous12-Aug-01 15:18
    memberAnonymous12-Aug-01 15:18 
    GeneralRe: Incorrect COM0 detection Pin
    Anonymous12-Aug-01 15:31
    memberAnonymous12-Aug-01 15:31 

    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
    Web02 | 2.8.170308.1 | Last Updated 4 Mar 2000
    Article Copyright 2000 by PJ Naughter
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid