Article View: borland.public.cppbuilder.nativeapi
Article #8822Re: Parallel port
From: Sam S. Firouz
Date: Mon, 20 Sep 2004 21:59
Date: Mon, 20 Sep 2004 21:59
131 lines
4780 bytes
4780 bytes
Lookup CM_Enumerate_Classes , EnumerateClass, SetupDiClassGuidsFromNameA,
SetupDiClassGuidsFromNameA, SetupDiGetClassDevs, ...
here is what I did to get the com ports and TAPI devices
void __fastcall TCommManager_S::EnumTapiAndCommPortNames (void)
{
HINSTANCE CfgMan;
CM_Enumerate_Classes enumClasses;
TStringList* TheList;
AnsiString ClName;
GUID ClGuid;
int ind;
bool DevPrs;
GUID* guidL;
unsigned long RequiredSize;
unsigned long MaxSize;
unsigned long j;
char DevN[MAX_DEV_LEN];
int numDev=0;
HDEVINFO NewDeviceInfoSet = NULL;
SP_DEVINFO_DATA DeviceInfoData={0};
TapiNames->Clear ();
CommPortNames->Clear ();
CfgMan = LoadLibrary ("cfgmgr32");
if (NULL == CfgMan)
return;
try
{
enumClasses =
(CM_Enumerate_Classes)GetProcAddress(CfgMan,"CM_Enumerate_Classes");
ind = 0;
guidL = NULL;
RequiredSize = 0;
MaxSize = 0;
while (EnumerateClass (ind++, &ClName, &ClGuid, &DevPrs, enumClasses))
{
if(DevPrs)
{
ClName = ClName.UpperCase();
if (ClName == "PORTS")
TheList = CommPortNames.get ();
else if (ClName == "MODEM")
TheList = TapiNames.get ();
else
TheList = NULL;
if (NULL != TheList)
{
DevPrs = SetupDiClassGuidsFromNameA(ClName.c_str (), guidL,
MaxSize * sizeof (GUID), &RequiredSize);
if (!DevPrs)
{
delete[] guidL;
guidL = new GUID[RequiredSize];
MaxSize = RequiredSize;
DevPrs = SetupDiClassGuidsFromNameA(ClName.c_str (),
guidL, MaxSize * sizeof (GUID), &RequiredSize);
}
if(!DevPrs)
RequiredSize = 0;
numDev = 0;
for (j = 0; j < RequiredSize; j++)
{
NewDeviceInfoSet = SetupDiGetClassDevs (&guidL[j], NULL,
NULL, DIGCF_PRESENT);
if (NewDeviceInfoSet != INVALID_HANDLE_VALUE)
{
while(true)
{
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
if(!SetupDiEnumDeviceInfo(NewDeviceInfoSet, numDev,
&DeviceInfoData))
{
SetupDiDestroyDeviceInfoList(NewDeviceInfoSet);
break;
}
DWORD typeP;
DWORD rs;
if(!SetupDiGetDeviceRegistryPropertyA(NewDeviceInfoSet, &DeviceInfoData,
SPDRP_FRIENDLYNAME, &typeP, DevN, MAX_DEV_LEN, &rs))
{
if(!SetupDiGetDeviceRegistryPropertyA(NewDeviceInfoSet, &DeviceInfoData,
SPDRP_DEVICEDESC, &typeP, DevN, MAX_DEV_LEN, &rs))
{
numDev++;
continue;
}
}
if ((ClName == "MODEM") || (strstr (DevN, "LPT") ==
NULL))
TheList->Add(DevN);
numDev++;
}
SetupDiDestroyDeviceInfoList(NewDeviceInfoSet);
}
}
}
}
}
}
__finally
{
FreeLibrary(CfgMan);
}
}
"Maswadeh" <n/a> wrote in message news:414f3e5c@newsgroups.borland.com...
> Hi.
>
> How to get a list of the parallel port of the computer. I want to get the
> name of
> the port (Lpt1, Lpt2, ...)j, and it's address (0x0378, ...).
>
> I use the parallel port for outputs some data to a machine.
>
> BCB 6.
> Windows ME/XP
>
> Thanks.
>
>
>
>
Technical Details
Message-ID:
<414f5138$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<414f3e5c@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,921592e14224713a X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Sam S. Firouz" <sfirouz@Hotmail.com> From: "Sam S. Firouz" <sfirouz@Hotmail.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <414f3e5c@newsgroups.borland.com> Subject: Re: Parallel port Date: Mon, 20 Sep 2004 17:59:11 -0400 Lines: 133 Organization: P.T.F.S. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 132.250.186.165 Message-ID: <414f5138$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1095717176 132.250.186.165 (20 Sep 2004 14:52:56 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.zanker.org!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail