function GetRegistryPropertyString(PnPHandle: HDEVINFO;
const DevData:
TSPDevInfoData; Prop: DWORD):
string;
var
BytesReturned: DWORD;
RegDataType: DWORD;
Buffer:
array [0..256]
of TCHAR;
begin
BytesReturned := 0;
RegDataType := 0;
Buffer[0] := #0;
SetupDiGetDeviceRegistryProperty(PnPHandle, DevData, Prop,
RegDataType, PByte(@Buffer[0]), SizeOf(Buffer), BytesReturned);
Result := Buffer;
end;
function GetCOMMDevices: TStringList;
const
ConnectorGUID = '
{4D36E978-E325-11CE-BFC1-08002BE10318}';
var
GUID: PGUID;
Buffer:
array[0..1023]
of TCHAR;
NameBuffer:
array[0..1023]
of Char;
Descriptionstr:
string;
PnPHandle: HDEVINFO;
DevData: TSPDevInfoData;
DeviceInterfaceData: TSPDeviceInterfaceData;
Success: LongBool;
BufSize: DWORD;
Devn: Integer;
S:
string;
aguid: Tguid;
begin
LoadSetupApi;
LoadConfigManagerApi;
GetMem(
GUID, SizeOf(TGUID));
guid^ := StringToGUID(ConnectorGUID);
SetupDiGetClassDescription(
GUID^, @Buffer[0], Length(Buffer), BufSize);
Descriptionstr := PTSTR(@Buffer[0]);
Result := TStringList.Create;
aguid :=
Guid^;
PnPHandle := SetupDiGetClassDevs(@AGUID,
nil, 0, DIGCF_PRESENT);
//PnPHandle := SetupDiGetClassDevs(@AGUID, nil, 0, 0);
if PnPHandle = Pointer(INVALID_HANDLE_VALUE)
then
begin
FreeMem(
GUID);
//Result := '';
Exit;
end;
Devn := 0;
repeat
DeviceInterfaceData.cbSize := SizeOf(TSPDeviceInterfaceData);
DevData.cbSize := SizeOf(DevData);
Success := SetupDiEnumDeviceInfo(PnPHandle, Devn, DevData);
if Success
then
begin
S := GetRegistryPropertyString(PnPHandle, DevData, SPDRP_FRIENDLYNAME);
if S = '
'
then
S := GetRegistryPropertyString(PnPHandle, DevData, SPDRP_DEVICEDESC);
Result.Add (S);
{
if Pos(UMtsappli, s) > 0 then
begin
Result := StrBetween(s, '(', ')');
end;
}
Inc(Devn);
end;
until not Success;
SetupDiDestroyDeviceInfoList(PnPHandle);
UnloadConfigManagerApi;
UnloadSetupApi;
end;