Code Snippet
// get a pointer to a combo
CComboBox* pCombo = (CComboBox*)GetDlgItem(IDC_COMBO_PORT);
// try ports between 1 and 128
for(int i=1; i<=128; i++)
{
CString strPort;
strPort.Format(_T("COM%d"),i);
DWORD dwSize = 0;
// allocate a minimum buffer
LPCOMMCONFIG lpCC = (LPCOMMCONFIG) new BYTE[1];
// call used only to get the actual required size
BOOL ret = GetDefaultCommConfig(strPort, lpCC, &dwSize);
delete [] lpCC;
// allocate the necessary buffer length
lpCC = (LPCOMMCONFIG) new BYTE[dwSize];
ret = GetDefaultCommConfig(strPort, lpCC, &dwSize);
// if call was successfull add the port
if(ret)
{
pCombo->AddString(strPort);
}
delete [] lpCC;
}