CEnumerateSerial LogoCEnumerateSerial v1.37

Welcome to CEnumerateSerial, A simple C++ class to enumerate the serial ports installed on your machine.

 

Features
Usage
Copyright
History
API Reference
Contacting the Author

 

 

 

Features

 

 

 

Usage

 

 

 

Copyright

 

 

 

History

v1.37 (15 January 2019)

v1.36 (16 September 2018)

v1.35 (8 July 2018)

v1.34 (19 May 2018)

v1.33 (15 November 2017)

v1.32 (25 September 2017)

v1.31 (2 July 2016)

v1.30 (28 May 2016)

v1.29 (28 March 2016)

v1.28 (20 December 2015)

v1.27 (1 December 2013)

v1.26 (3 August 2013)

v1.25 (28 July 2013)

v1.24 (10 January 2013)

v1.23 (15 October 2012)

v1.22 (28 March 2011)

v1.21 (27 March 2010)

v1.20 (30 April 2009)

v1.19 (29 November 2008)

v1.18 (23 November 2008)

v1.17 (20 March 2008)

v1.16 (5 July 2007)

v1.15 (9 June 2007)

v1.14 (29 January 2007)

v1.13 (8 November 2006)

v1.12 (9 July 2006)

v1.11 (13 May 2004)

v1.10 (12 December 2003)

v1.09 (20 September 2003)

v1.08 (22 May 2003)

v1.07 (13 August 2001)

v1.06 (11 August 2001)

v1.05 (25 June 2001)

v1.04 (29 March 2001)

v1.03 (17 May 2000)

v1.02 (12 December 1999)

v1.01 (23 February 1999)

v1.0 (3 November 1998)

 

 

 

API Reference

CEnumerateSerial::UsingCreateFile

BOOL CEnumerateSerial::UsingCreateFile(CPortsArray& ports);

Parameters

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

Remarks

This function uses the CreateFile method of detecting serial ports. This will work on all Win32 OS'es, but requires actually opening the port.

 

CEnumerateSerial::UsingQueryDosDevice

BOOL CEnumerateSerial::UsingQueryDosDevice(CPortsArray& ports);

Parameters

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

Remarks

This function uses the QueryDosDevice method of detect serial ports. Please note that this only works correctly on NT 3.x or later and not Windows 9x.

 

CEnumerateSerial::UsingGetDefaultCommConfig

BOOL CEnumerateSerial::UsingGetDefaultCommConfig(CPortsArray& ports);

Parameters

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

Remarks

This function uses the GetDefaultCommConfig method of detect serial ports. Please note that this is the most compatible way of detecting serial ports and will work on all Win32 OS'es from Windows 95 onwards but also happens to be the slowest.

 

CEnumerateSerial::UsingSetupAPI1

BOOL CEnumerateSerial::UsingSetupAPI1(CPortAndNamesArray& ports);

Parameters

ports Upon return this array will contain the port numbers and friendly names of all the serial ports installed on the computer

Remarks

This function uses the Device Manager "SetupDi.." APIs and the value GUID_DEVINTERFACE_COMPORT device interface class to detect serial ports. Please note that this will only work on Windows 2000 or later.

 

CEnumerateSerial::UsingSetupAPI2

BOOL CEnumerateSerial::UsingSetupAPI2(CPortAndNamesArray& ports);

Parameters

ports Upon return this array will contain the port numbers and friendly names of all the serial ports installed on the computer

Remarks

This function uses the Device Manager "SetupDi.." APIs and the "Ports" device information set to detect serial ports. The code of course implements logic to exclude parallel ports from the returned array as they are included in the "Ports" device information set in addition to serial ports. This approach will work on all Win32 OS'es from Windows 95 onwards.

 

CEnumerateSerial::UsingEnumPorts

BOOL CEnumerateSerial::UsingEnumPorts(CPortAndNamesArray& ports);

Parameters

ports Upon return this array will contain the port numbers and friendly names of all the serial ports installed on the computer

Remarks

This function uses the Win32 SDK call "EnumPorts"  APIs to detect serial ports. This will work on all Win32 OS'es from Windows 95 onwards.

 

CEnumerateSerial::UsingWMI

BOOL CEnumerateSerial::UsingWMI(CPortAndNamesArray&  ports);

Parameters

ports Upon return this array will contain the port numbers and friendly names of all the serial ports installed on the computer

Remarks

This function uses the WMI COM interfaces to detect serial ports. This will only work on Windows NT 4 SP4 or later (i.e versions of Windows on which WMI is available).

 

CEnumerateSerial::UsingComDB

BOOL CEnumerateSerial::UsingComDB(CPortsArray& ports);

Parameters

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

Remarks

This function uses the uses the so called "COM Database" functions which are part of the Windows DDK which device drivers can use to support claiming an unused port number when the device driver is being installed. Please note that the list returning from this function will only report used port numbers. The device may or may not be actually present, just that the associated port number is currently "claimed". This will only work on Windows 2000 or later. A final note is that the ComDB functions require UAC elevation if UAC is enabled.

 

CEnumerateSerial::UsingRegistry

BOOL CEnumerateSerial::UsingRegistry(CNamesArray& ports);

Parameters

ports Upon return this array will contain the names of all the serial ports installed on the computer

Remarks

This function detects the install ports by enumerating the values contained at the registry key HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM. This is the same registry location as used by the .NET method SerialPort::GetPortNames. It also seems to be the way which HyperTerminal uses to enumerate the ports which it offers in its connect dialog. This method has the advantage that it returns serial ports which do not adhere to the "COMX" naming convention. For example if you use the com0com driver from http://com0com.sourceforge.net/, you will see the "CNC0A" and "CNC0B" ports which it creates by default being returned from "UsingRegistry". This method will work on all versions of Windows from Windows 98 onwards.

 

 

 

Contacting the Author

PJ Naughter
Email: pjna@naughter.com
Web: http://www.naughter.com
15 January 2019