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
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
i = 2;
for(i=0; i < Enumerator.GetTotalComs(); i++)
if(Enumerator.GetPortSimpleKey(i) == "Serial2")
portName = Enumerator.GetPortName(i);
portKey = Enumerator.GetPortKey(i);
portIndex = Enumerator.GetPortIndex(i);
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 http://www.advatronix.com/. There, you can also download a pre-built executable.