FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour List of COM Ports
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
List of COM Ports
Posted: Sun Feb 17, 2013 01:04 AM

Hi,

Is there a way to get a list of the available COM ports on a system?

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: List of COM Ports
Posted: Mon Feb 18, 2013 04:19 AM
I think you can get the list by reading the following registry entries

HKEY_LOCAL_MACHINE\Hardware\DeviceMap\SerialComm

Regards
Anser
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: List of COM Ports
Posted: Mon Feb 18, 2013 07:54 PM
Hi Anser,

I checked my registry ... you are correct. They are listed there.
Now the question is, how would I get an array of the com ports when I don't know what the key names will be?

Thanks,

Jeff Barnes



(FWH 16.11, xHarbour 1.2.3, Bcc730)
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: List of COM Ports
Posted: Tue Feb 19, 2013 07:34 AM
Jeff,

you can use ::EnumVkey() from my reg32.prg

Code (fw): Select all Collapse
//-------------------------------------------------------------------------//
METHOD EnumKey () CLASS TReg32

LOCAL i := 0, nError := 0
LOCAL cBuffer := Space (255)
LOCAL nBufSize := 255
LOCAL cClass := Space (255)
LOCAL nClsSize := 255
LOCAL aRet := {}

 While (nError := RegEnumKeyExA( ::nHandle, i++, @cBuffer, nBufSize,0,cClass, nClsSize )) == ERROR_SUCCESS

    cBuffer := StrTran (cBuffer,",","\")         // Replace "," with "\"
    AADD (aRet,cBuffer)

 End

::nError := nError

RETURN (aRet)

//-------------------------------------------------------------------------//
DLL32 static ;
FUNCTION RegEnumKeyExA(nhKey      AS LONG   ,;
                       nIndex     AS LONG   ,;
                       @cBuffer   AS LPSTR  ,;   //By reference
                       @nBufSize  AS PTR    ,;   //By reference
                       nReserved  AS LONG   ,;   //Must be NULL
                       @cClass    AS LPSTR  ,;   //By reference (can be NULL)
                       @nClsSize  AS PTR    ,;   //By reference (can be NULL)
                       @pFileTime AS PTR    );   //By reference (can be NULL)
         ;
         AS LONG PASCAL LIB "ADVAPI32.DLL"
kind regards

Stefan

Continue the discussion