Results 1 to 5 of 5

Thread: I want to know which com port my modem is using??

  1. #1

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241

    Exclamation

    hi,
    I want to know which com port my modem using, ofcourse i want to knpw that using VB code,Please Help

  2. #2
    Lively Member
    Join Date
    Oct 1999
    Posts
    66
    Maybe this helps a little?

    '// API Declarations
    Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
    Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

    '// API Structures
    Public Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
    End Type

    '// API constants
    Public Const FILE_SHARE_READ = &H1
    Public Const FILE_SHARE_WRITE = &H2
    Public Const OPEN_EXISTING = 3
    Public Const FILE_ATTRIBUTE_NORMAL = &H80


    '// Return TRUE if the COM exists, FALSE if the COM does not exist
    Public Function COMAvailable(COMNum As Integer) As Boolean
    Dim hCOM As Long
    Dim ret As Long
    Dim sec As SECURITY_ATTRIBUTES

    '// try to open the COM port
    hCOM = CreateFile("COM" & COMNum & "", 0, FILE_SHARE_READ + _
    FILE_SHARE_WRITE, sec, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
    If hCOM = -1 Then
    COMAvailable = False
    Else
    COMAvailable = True
    '// close the COM port
    ret = CloseHandle(hCOM)
    End If
    End Function

    Then, use the code below to go through all the possible COM ports, and find if they are available or not. This code presumes that you have a Combo box named cboComm.

    Private Sub ListComPorts()
    Dim i As Integer

    cboComm.Clear
    For i = 1 To 16
    If COMAvailable(i) Then
    cboComm.AddItem i
    End If
    Next
    cboComm.ListIndex = 0
    End Sub

  3. #3

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241
    Thanx man, but when i tried it, nothing happened, i mean it said that no com port in my system is active, the combobox shows nothing at all, What do ya think??

  4. #4
    Lively Member
    Join Date
    Oct 1999
    Posts
    66
    I'm sorry man, I haven't tried it yet. I got it from
    http://www.vbweb.co.uk

  5. #5

    Thread Starter
    Addicted Member Mih_Flyer's Avatar
    Join Date
    Mar 2000
    Location
    some place there
    Posts
    241
    Thanx alot any way

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width