kvk1989 2 Posted March 26, 2022 hi, i get comport in combobox but i want add modem port in combobox can someone help me ? here is my comport codes and here modem port registry guid <{4d36e96d-e325-11ce-bfc1-08002be10318}> thanks !! < > unit USBPort; interface uses Winapi.Windows, System.SysUtils, System.Variants, System.Classes, SetupApi, System.Win.Registry, Vcl.StdCtrls, Vcl.Graphics; const GUID_DEVINTERFACE_COMPORT: TGUID = '{86E0D1E0-8089-11D0-9CE4-08003E301F73}'; procedure SearchPort(cb: Tcombobox); Function GetPort(port:string):string; implementation uses Unit1; function SetupEnumAvailableComPorts: TstringList; var RequiredSize: Cardinal; GUIDSize: DWORD; Guid: TGUID; DevInfoHandle: HDEVINFO; DeviceInfoData: TSPDevInfoData; MemberIndex: Cardinal; PropertyRegDataType: DWord; RegProperty: Cardinal; RegTyp: Cardinal; Key: Hkey; Info: TRegKeyInfo; S1, S2: string; hc: THandle; begin Result := Nil; if not LoadsetupAPI then exit; try GUIDSize := 1; if SetupDiClassGuidsFromName('Ports', @Guid, GUIDSize, RequiredSize) then begin DevInfoHandle := SetupDiGetClassDevs(@Guid, Nil, 0, DIGCF_PRESENT); if Cardinal(DevInfoHandle) <> Invalid_Handle_Value then begin try MemberIndex := 0; result := TStringList.Create; repeat FillChar(DeviceInfoData, SizeOf(DeviceInfoData), 0); DeviceInfoData.cbSize := SizeOf(DeviceInfoData); if not SetupDiEnumDeviceInfo(DevInfoHandle, MemberIndex, DeviceInfoData) then break; RegProperty := SPDRP_FriendlyName; SetupDiGetDeviceRegistryProperty(DevInfoHandle, DeviceInfoData, RegProperty, PropertyRegDataType, NIL, 0, RequiredSize); SetLength(S1, RequiredSize); if SetupDiGetDeviceRegistryProperty(DevInfoHandle, DeviceInfoData, RegProperty, PropertyRegDataType, @S1[1], RequiredSize, RequiredSize) then begin Key := SetupDiOpenDevRegKey(DevInfoHandle, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); if Key <> INValid_Handle_Value then begin FillChar(Info, SizeOf(Info), 0); if RegQueryInfoKey(Key, nil, nil, nil, @Info.NumSubKeys, @Info.MaxSubKeyLen, nil, @Info.NumValues, @Info.MaxValueLen, @Info.MaxDataLen, nil, @Info.FileTime) = ERROR_SUCCESS then begin RequiredSize := Info.MaxValueLen + 1; SetLength(S2, RequiredSize); if RegQueryValueEx(Key, 'PortName', Nil, @RegTyp, @S2[1], @RequiredSize) = Error_Success then begin if (Pos('COM', S2) = 1) then begin hc := CreateFile(pchar('\\.\' + S2 + #0), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if hc <> INVALID_HANDLE_VALUE then begin Result.Add(StrPas(PChar(S1))); CloseHandle(hc); end; end; end; end; RegCloseKey(Key); end; end; Inc(MemberIndex); until False; if Result.Count = 0 then begin Result.Free; Result := NIL; end finally SetupDiDestroyDeviceInfoList(DevInfoHandle); end; end; end; finally UnloadSetupApi; end; end; procedure SearchPort(cb: Tcombobox); var ComPortString: TStringList; i: integer; nameport: string; begin cb.Items.Clear; ComPortString := TStringList.Create; try ComPortString := SetupEnumAvailableComPorts; if (ComPortString <> nil) and (ComPortString.Count > 0) then begin for i := 0 to ComPortString.Count - 1 do begin nameport := ComPortString[i].trim; cb.items.add(nameport); cb.itemindex := 0; end; end; finally ComPortString.free; end; end; Function GetPort(port:string):string; begin result := RightStr(port, 7).Replace('(', '').Replace('C', '').Replace('O', '').Replace('M', '').Replace(')', '').trim; end; end. Share this post Link to post
Angus Robertson 574 Posted March 26, 2022 I released Magenta Serial Port Detection Component free earlier this year, part of Magenta Hardware Components at: https://www.magsys.co.uk/delphi/maghardware.asp It finds serial ports by several methods. Angus 1 Share this post Link to post
kvk1989 2 Posted March 26, 2022 14 hours ago, Angus Robertson said: I released Magenta Serial Port Detection Component free earlier this year, part of Magenta Hardware Components at: https://www.magsys.co.uk/delphi/maghardware.asp It finds serial ports by several methods. Angus Thanks for your component but there is any demos project available? Share this post Link to post
Angus Robertson 574 Posted March 27, 2022 The Magenta Hardware Components download includes compiled demos for all the components. Angus 1 Share this post Link to post
kvk1989 2 Posted March 28, 2022 (edited) 19 hours ago, Angus Robertson said: The Magenta Hardware Components download includes compiled demos for all the components. Angus hi, i want to add modem port see here in this pic Edited March 28, 2022 by kvk1989 Share this post Link to post
Angus Robertson 574 Posted March 28, 2022 The Ansi warnings relate to my updated version of AsyncPro adport.pas unit that allows named COM ports to be opened, but this is for 4.06, not recent Unicode versions, you'd need to update whatever Async Pro you are using with my very minor changes. Strange the component did not find one of your modems, although it did find 18 other COM ports you've previously installed. Can only guess Samsung has installed it using keys, you'd need to check what they are and update the component. Angus Share this post Link to post
Angus Robertson 574 Posted March 29, 2022 Did you work out the Device Installation Class under which your modems are installed, other than Modem or Ports? It should be a single line change to enumerate a new class. Angus 1 Share this post Link to post
kvk1989 2 Posted March 30, 2022 On 3/26/2022 at 3:03 PM, Angus Robertson said: 8 hours ago, Angus Robertson said: Did you work out the Device Installation Class under which your modems are installed, other than Modem or Ports? It should be a single line change to enumerate a new class. Angus yes today I have to work on it and then I will tell what I have found Share this post Link to post