Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2007 Jul : Detecting a modem
| Subject: | Detecting a modem |
| Posted by: | "J.Rick Luttrell" (luttre..@earthlink.net) |
| Date: | Thu, 12 Jul 2007 09:08:15 |
I have an application where the user must select an available comport for communication
with a serial device. Getting a list of the attached devices is not a problem using
TCommConfig but I'd like to not show any ports that are attached to a modem.
Would using GetCommModemStatus be an acceptable method to filter out a modem on a port ?
function Tcdm.ModemOnPort(const ComNo: string): boolean;
var
hCommFile: THandle;
ModemStat: DWord;
begin
hCommFile := CreateFile(PChar(ComNo),
GENERIC_READ, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if hCommFile = INVALID_HANDLE_VALUE then
result := false
else if (GetCommModemStatus(hCommFile, ModemStat) <> false) and (ModemStat <> 0) then
result := true {_Modem}
else
result := false; {_Not a Modem}
CloseHandle(hCommFile);
end;
Suggestions appreciated,
-Rick