Newsgroup: it.comp.lang.visual-basic
Titolo: Numero e nome porte COM

Ciao a tutti,
quali sono i componenti o funzioni/API da utilizzare per conoscere il numero
ed il nome di tutte le porte COM installate ed attive su un determinato PC?
Grazie a tutti,
Dave

Tutto questo è tratto da AllAPInet!!! ... fossi in te lo installerei!
Declare Function EnumPorts Lib "winspool.drv" Alias "EnumPortsA" (ByVal
pName As String, ByVal Level As Long, ByVal lpbPorts As Long, ByVal cbBuf As
Long, pcbNeeded As Long, pcReturned As Long) As Long
Parametri:
· pName
Pointer to a null-terminated string that specifies the name of the server
whose printer ports you wish to enumerate.
If pName is NULL, the function enumerates the local machine's printer ports.
· Level
Specifies the type of data structures pointed to by pPorts.
This value can be 1 or 2.
· pPorts
Pointer to a buffer that receives an array of PORT_INFO_1 or PORT_INFO_2
structures. Each structure contains data that describes an available printer
port. The value of Level specifies the type of structure. A Level value of 1
specifies PORT_INFO_1 structures. A Level value of 2 specifies PORT_INFO_2
structures.
· cbBuf
Specifies the size, in bytes, of the buffer pointed to by pPorts.
· pcbNeeded
Pointer to a variable that the function sets to the size, in bytes, of the
data that enumerates the printer ports. If cbBuf is smaller than this value,
EnumPorts fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the
variable pointed to by pcbNeeded represents the required buffer size. If
cbBuf is equal to or greater than this value, the variable pointed to by
pcbNeeded represents the number of bytes stored into the buffer.
· pcReturned
Pointer to a variable that the function sets to the number of PORT_INFO_*
structures that it stores into the buffer pointed to by pPorts. This is the
number of printer ports that are available on the specified server.
Declare Function ConfigurePort Lib "winspool.drv" Alias "ConfigurePortA"
(ByVal pName As String, ByVal hwnd As Long, ByVal pPortName As String) As
Long
Parametri:
· pName
Points to a null-terminated string that specifies the name of the server on
which the specified port exists. If this parameter is NULL, the port is
local.
· hWnd
Identifies the parent window of the port-configuration dialog box.
· pPortName
Points to a null-terminated string that specifies the name of the port to be
configured.
Ciao, Vincenzo

ed il nome di tutte le porte COM installate ed attive su un determinato PC?
questa va:
'queste sono info da MSDN perchč viene da un esempio trovato su un
'sito che non funzionava:
'  typedef struct _DCB {  DWORD DCBlength;  DWORD BaudRate;  DWORD
' fBinary  :1;  DWORD fParity  :1;  DWORD fOutxCtsFlow  :1;
' DWORD fOutxDsrFlow  :1;  DWORD fDtrControl  :2;
' DWORD  fDsrSensitivity  :1;  DWORD fTXContinueOnXoff  :1;
' DWORD fOutX  :1;  DWORD fInX  :1;  DWORD fErrorChar  :1;
' DWORD fNull  :1;  DWORD fRtsControl  :2; DWORD fAbortOnError  :1;
' DWORD fDummy2  :17;  WORD wReserved;  WORD XonLim;  WORD XoffLim; 
' BYTE ByteSize; BYTE Parity;  BYTE StopBits;
' char XonChar;  char XoffChar;  char ErrorChar;  char EofChar;
'  char EvtChar;  WORD wReserved1;} DCB;
Private Type DCB
        DCBlength As Long
        BaudRate As Long
        fBinary As Long
        fParity As Long
        fOutxCtsFlow As Long
        fOutxDsrFlow As Long
        fDtrControl As Long
        fDsrSensitivity As Long
        fTXContinueOnXoff As Long
        fOutX As Long
        fInX As Long
        fErrorChar As Long
        fNull As Long
        fRtsControl As Long
        fAbortOnError As Long
        fDummy2 As Long
        wReserved As Integer
        XonLim As Integer
        XoffLim As Integer
        ByteSize As Byte
        Parity As Byte
        StopBits As Byte
        XonChar As Byte
        XoffChar As Byte
        ErrorChar As Byte
        EofChar As Byte
        EvtChar As Byte
        wReserved1 As Integer
End Type
'queste sono info da MSDN
' typedef struct _COMM_CONFIG {  DWORD dwSize;  WORD wVersion;
'  WORD wReserved;  DCB dcb ;DWORD dwProviderSubType;
' DWORD dwProviderOffset;  DWORD dwProviderSize;
' WCHAR wcProviderData[1];} COMMCONFIG, *LPCOMMCONFIG;
Private Type COMMCONFIG
    dwSize As Long
    wVersion As Integer
    wReserved As Integer
    dcbx As DCB
    dwProviderSubType As Long
    dwProviderOffset As Long
    dwProviderSize As Long
    wcProviderData As Byte
End Type
Private Declare Function GetDefaultCommConfig Lib "Kernel32" Alias
"GetDefaultCommConfigA" (ByVal lpszName As String, lpCC As COMMCONFIG,
lpdwSize As Long) As Long
------------------------------------------------------------------------------------------
Public Function EnumSerPorts(port As Integer) As Long
'returns non-zero value if the port exists
        Dim cc As COMMCONFIG, ccsize As Long
        ccsize = LenB(cc)     'gets the size of COMMCONFIG structure
        EnumSerPorts = GetDefaultCommConfig("COM" & CStr(port) &
Chr(0), cc, ccsize)
       ' Debug.Print Err.LastDllError
End Function
------------------------------------------------------------------------------------------
Private Sub Form_Load()
' io uso una matrice di controlli per selezionare la porta
If EnumSerPorts(1) = 0 Then OpCom(1).Enabled = False
If EnumSerPorts(2) = 0 Then OpCom(2).Enabled = False
If EnumSerPorts(3) = 0 Then OpCom(3.)Enabled = False
If EnumSerPorts(4) = 0 Then OpCom(4).Enabled = False
end sub
ciao
 Stefano