The EnumSerialPorts v1.20 suggested by Nick D uses nine different methods to list the serial ports! We're certainly not short on choice, though the results seem to vary.
The EnumSerialPorts v1.20 suggested by Nick D uses nine different methods to list the serial ports! We're certainly not short on choice, though the results seem to vary. To save others the trouble, I'll list them here and indicate their success in finding the com0com ports on my PC (XP Pro SP2): CreateFile("COM" + 1->255) as suggested by Wael Dalloul?
Found com0com ports, took 234ms. QueryDosDevice()? Found com0com ports, took 0ms.
GetDefaultCommConfig("COM" + 1->255)? Found com0com ports, took 235ms. "SetupAPI1" using calls to SETUPAPI.
DLL? Found com0com ports, also reported "friendly names", took 15ms. "SetupAPI2" using calls to SETUPAPI.
DLL? Did not find com0com ports, reported "friendly names", took 32ms. EnumPorts()?
Reported some non-COM ports, did not find com0com ports, took 15ms. Using WMI calls? Found com0com ports, also reported "friendly names", took 47ms.COM Database using calls to MSPORTS.
DLL? /? Reported some non-COM ports, found com0com ports, took 16ms.
Iterate over registry key HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM? Found com0com ports, took 0ms. This is apparently what SysInternals PortMon uses.
Based on those results I think the WMI method probably suits my requirements best as it is relatively fast and as a bonus it also gives the friendly names (e.g. "Communications Port (COM1)", "com0com - serial port emulator").Thanks.
GrahamS, I suggest you to accept your answer. +1 – Nick Dandoulakis Sep 8 '09 at 15:48 Thanks Nick. Done.
:) – GrahamS Sep 9 '09 at 14:18.
You can make loop for example from 1 to 50 and try to open each port. If the port is available, the open will work. If the port is in use, you'll get a sharing error.
If the port is not installed, you'll get a file not found error. To open the port use CreateFile API: int Port =CreateFile("Com1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); then check the result.
This works, though 1 to 255 might be a better range. – GrahamS Sep 8 '09 at 14:25.
It appears that it's not a simple task. Check out this: EnumSerialPorts v1.20.
Thanks Nick, I've expanded a little on your answer below. If no one comes along with anything more definite then I'll accept your response. – GrahamS Sep 8 '09 at 14:22.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.