|
发表于 2006-4-3 18:03:00
|
显示全部楼层
for( int i=1; i<256; i++ )
{
CString sPort;
sPort.Format(_T("\\\\.\\COM%d"),i);
BOOL bSuccess=FALSE;
HANDLE hPort=::CreateFile(sPort, GENERIC_READ|GENERIC_WRITE, 0, 0,
OPEN_EXISTING, 0, 0);
if( hPort == INVALID_HANDLE_VALUE)
{
DWORD dwError=GetLastError();
if( dwError == ERROR_ACCESS_DENIED)
bSuccess=TRUE;
}
else
{
bSuccess=TRUE;
CloseHandle(hPort);
}
if( bSuccess )
{
CString str;
str.Format("COM%d",i);
m_Port.AddString(str);
}
}
m_Port.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
} |
|