Thread View: borland.public.cppbuilder.nativeapi
3 messages
3 total messages
Started by northern_RATT
Thu, 29 Nov 2007 04:25
Enum com ports ignore modems etc
Author: northern_RATT
Date: Thu, 29 Nov 2007 04:25
Date: Thu, 29 Nov 2007 04:25
17 lines
1353 bytes
1353 bytes
Hi Folks; I need to populate a menu w/ available COM ports. I know how to do this with CreatFile(dwAccess=0). Fine & Dandy, But if this port is attached to a modem, IR port, Bluetooth device then I want to skip it. I'm only interested in RS232, 9 pin D connector, COM ports. So my question is: If I get a valid handle back form CreateFile is there a good way to determine what is on the other end? Thanks Drew
Re: Enum com ports ignore modems etc
Author: Colin B Maharaj
Date: Thu, 29 Nov 2007 23:39
Date: Thu, 29 Nov 2007 23:39
124 lines
4411 bytes
4411 bytes
Nope, you may need to do some further digging
to enumerate modems in the registry, then probably
subtract this from all available ports.
I have some quick and dirty code to enumerate
existing COM ports, weather open or not.
However, it is not perfect, and you will need to
clean it up yourself. :)
Good luck....
//-----------------------------------------------------------------------------
bool COM1,COM2,COM3,COM4,COM5,COM6,COM7,COM8;
bool COMExists(char *ComStr)
{
HKEY hKey;
DWORD keyType = 0;
DWORD retValue = 0;
DWORD keyLength = 0;
char *t = new char [MAX_PATH];
char *CV = new char [256];
strcpy(CV, "Hardware\\DeviceMap\\SerialComm"); // safe
retValue = RegOpenKeyEx(HKEY_LOCAL_MACHINE, CV, NULL, KEY_READ, &hKey);
if (retValue != ERROR_SUCCESS)
{
delete []CV;
delete []t;
return false;
}
RegQueryValueEx(hKey, ComStr, NULL, &keyType, NULL, &keyLength);
retValue = RegQueryValueEx(hKey, ComStr, NULL, &keyType, (UCHAR *)t,
&keyLength);
RegCloseKey(hKey);
if (retValue != ERROR_SUCCESS)
{
delete []CV;
delete []t;
return false;
}
if (strcmp(t, "COM1")==0) COM1 = true;
if (strcmp(t, "COM2")==0) COM2 = true;
if (strcmp(t, "COM3")==0) COM3 = true;
if (strcmp(t, "COM4")==0) COM4 = true;
if (strcmp(t, "COM5")==0) COM5 = true;
if (strcmp(t, "COM6")==0) COM6 = true;
if (strcmp(t, "COM7")==0) COM7 = true;
if (strcmp(t, "COM8")==0) COM8 = true;
delete []CV;
delete []t;
return true;
}
//-----------------------------------------------------------------------------
AnsiString EnumSerialPorts()
{
AnsiString COMcsv = "";
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize = sizeof(osv);
GetVersionEx(&osv);
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
COMExists("\\Device\\Serial0");
COMExists("\\Device\\Serial1");
COMExists("\\Device\\Serial2");
COMExists("\\Device\\Serial3");
COMExists("\\Device\\Serial4");
COMExists("\\Device\\Serial5");
COMExists("\\Device\\Serial6");
COMExists("\\Device\\Serial7");
}
else
{
COMExists("COM1");
COMExists("COM2");
COMExists("COM3");
COMExists("COM4");
COMExists("COM5");
COMExists("COM6");
COMExists("COM7");
COMExists("COM8");
}
if (COM1 == true) COMcsv = "COM1";
if (COM2 == true) COMcsv += "\,COM2";
if (COM3 == true) COMcsv += "\,COM3";
if (COM4 == true) COMcsv += "\,COM4";
if (COM5 == true) COMcsv += "\,COM5";
if (COM6 == true) COMcsv += "\,COM6";
if (COM7 == true) COMcsv += "\,COM7";
if (COM8 == true) COMcsv += "\,COM8";
return COMcsv;
}
//-----------------------------------------------------------------------------
northern_RATT wrote:
> Hi Folks;
>
> I need to populate a menu w/
> available COM ports. I know how to
> do this with CreatFile(dwAccess=0).
> Fine & Dandy, But if this port is
> attached to a modem, IR port,
> Bluetooth device then I want to
> skip it. I'm only interested in
> RS232, 9 pin D connector, COM
> ports. So my question is: If I get
> a valid handle back form CreateFile
> is there a good way to determine
> what is on the other end?
>
> Thanks
> Drew
>
>
Re: Enum com ports ignore modems etc
Author: Boba
Date: Tue, 01 Jan 2008 04:16
Date: Tue, 01 Jan 2008 04:16
5 lines
1134 bytes
1134 bytes
"Colin B Maharaj" <noreply@myhost.com> wrote in message news:474f4db2$1@newsgroups.borland.com... > ... just wondering what is the reason for you to use advapi and not kernel?
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads