windows c++ get available com ports code example
Example: c++ com port list
#include <iostream>
#include <string>
#include <Windows.h>
bool SelectComPort()
{
char lpTargetPath[5000];
bool gotPort = false;
for (int i = 0; i < 255; i++)
{
std::string str = "COM" + std::to_string(i);
DWORD test = QueryDosDevice(str.c_str(), lpTargetPath, 5000);
if (test != 0)
{
std::cout << str << ": " << lpTargetPath << std::endl;
gotPort = true;
}
if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
}
}
return gotPort;
}