| 
사용방법
 2개의 파일을  현재 작업 폴더에 복사하시고
 
 Project 메뉴에서 Add To Project를 선택해서 uFindComport.pas를 추가합니다.
 
 그리고 GetcomportList를 사용하고자 하는 *.cpp 에서  상단에   #include "uFindComport.hpp" 넣어 주시고
 
 ComboBox나 ListBox를 하나 추가 하시고....
 
 GetComportList( ListBox1->Items, true ); --> 사용가능한 것인지 Check하여 가능한 것만 추출하고...
 GetCcomportList( ListBox1->Items );       --> Windows에 등록된 모든 Comport를 추출합니다.
 
 이 자료의 출처는 www.delphi.co.kr의 딥란의 최용일 님께서 올린 것입니다.
 
 이런 것이 devpia에도 있는데... 무엇이 좀 복잡해 보여서... 또 빌더로 바꾸어야 하니...
 
 그러다 pascal로 된 이것을 찾게 되었습니다.  유용하게 사용하시길....
 
 아래는 소스인데... 파일 안받고 그냥 차고할실 분을 위해....
 
 function ValidateComPort(comport : PChar): Boolean;
 // COM포트가 사용가능한지 알아낸다.
 var
 PortHandle: THandle;
 begin
 Result := False;
 PortHandle := CreateFile(comport, GENERIC_READ or GENERIC_WRITE, 0, nil,
 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
 if (PortHandle <> INVALID_HANDLE_VALUE) then
 begin
 Result := True;
 CloseHandle(PortHandle);
 end;
 end;
 
 procedure GetComportList(List: TStrings; OnlyAvail: Boolean = False);
 // 현재 인스톨된 COM포트 목록을 구한다.
 var
 RegFile: TRegistry;
 DeviceList: TStrings;
 DeviceCount: Integer;
 CanAddPort: Boolean;
 CurrentPort: string;
 begin
 if Assigned(List) then
 begin
 RegFile := TRegistry.Create;
 try
 RegFile.RootKey := HKEY_LOCAL_MACHINE;
 RegFile.OpenKeyReadOnly('hardware\devicemap\serialcomm');
 DeviceList := TStringList.Create;
 try
 RegFile.GetValueNames(DeviceList);
 List.Clear;
 for DeviceCount := 0 to DeviceList.Count - 1 do
 begin
 CurrentPort := RegFile.ReadString(DeviceList.Strings[DeviceCount]);
 if OnlyAvail then
 CanAddPort := Validatecomport(PChar(CurrentPort))
 else
 CanAddPort := True;
 if CanAddPort then
 List.Add(CurrentPort);
 end;
 finally
 DeviceList.Free;
 end;
 RegFile.CloseKey;
 finally
 RegFile.Free;
 end;
 end;
 end;
 |