Results 1 to 6 of 6

Thread: modem access

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Exclamation modem access

    I need to know if there is an api call to access and dial up with a modem... Is there? if so, where can I find it? I've looked everywhere I can think of...

    Any help would be relished!

    thanx,
    squirrely1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  2. #2
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    This is a Form and Module that shows how to open a com port and dial out.

    Form1
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     DialNumber "767-8900", "COM1"
    5. End Sub
    6.  
    7.  
    8.  
    9. Private Sub DialNumber(sPhoneNumber, sCommPort As String)
    10.    
    11.     Dim sMsg As String
    12.     Dim bModemCommand() As Byte, sCommand  As String
    13.     Dim lOpenPort As Long
    14.     Dim lRet As Long, lRetBytes As Long, i As Integer
    15.    
    16.     If MsgBox("Please pickup the phone and choose OK to dial " & sPhoneNumber, vbOKCancel, App.Title) = vbCancel Then
    17.         Exit Sub
    18.     End If
    19.    
    20.     lOpenPort = CreateFile(sCommPort, &HC0000000, 0, 0, OPEN_ALWAYS, 0, 0)
    21.     If lOpenPort = -1 Then
    22.         sMsg = "Unable to open communication port " & sCommPort
    23.         GoTo Err_DialNumber
    24.     End If
    25.    
    26.     sCommand = "ATDT" & sPhoneNumber & vbCrLf
    27.     ReDim bModemCommand(Len(sCommand))
    28.     For i = 0 To Len(sCommand) - 1
    29.         bModemCommand(i) = Asc(Mid$(sCommand, i + 1, 1))
    30.     Next
    31.    
    32.     lRet = WriteFile(lOpenPort, bModemCommand(0), Len(sCommand), lRetBytes, 0)
    33.    
    34.     If lRet = 0 Then
    35.         sMsg = "Unable to dial number " & sPhoneNumber
    36.         GoTo Err_DialNumber
    37.     End If
    38.    
    39.     lRet = FlushFileBuffers(lOpenPort)
    40.    
    41.     MsgBox "Click OK when the phone finishes dialing.    "
    42.     sCommand = "ATH0" & vbCrLf
    43.     ReDim bModemCommand(Len(sCommand))
    44.  
    45.     For i = 0 To Len(sCommand) - 1
    46.         bModemCommand(i) = Asc(Mid$(sCommand, i + 1, 1))
    47.     Next
    48.    
    49.     lRet = WriteFile(lOpenPort, bModemCommand(0), Len(sCommand), lRetBytes, 0)
    50.    
    51.     lRet = FlushFileBuffers(lOpenPort)
    52.    
    53.     lRet = CloseHandle(lOpenPort)
    54.    
    55.     Exit Sub
    56.    
    57. Err_DialNumber:
    58.     MsgBox sMsg & vbCr & vbCr & "Make sure no other devices are using Com port " & sCommPort
    59.    
    60.    
    61. End Sub

    Module
    VB Code:
    1. Option Explicit
    2. Public Const OPEN_EXISTING = 3
    3. Public Const OPEN_ALWAYS = 4
    4.  
    5. Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
    6. Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes&, ByVal hTemplateFile As Long) As Long
    7. Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    8. Declare Function FlushFileBuffers Lib "kernel32" (ByVal hFile As Long) As Long

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Question

    Thank you for the code, but I'm afraid it's not working for me... Is I copy and pasted it to my program, but my modem isn't dialing... Is there any way to make the modem dial-up according to information already in a "dial-up connection" in the Windows Dial-up Networking? The name of the connection is cswnet...

    thank you,
    squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  4. #4
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    To actually "dial-up" automatically with these functions, you need to set the Internet Explorer settings to auto-dial and use the following function to dial-up the DEFAULT ISP providor you have on your system. To set IE, right click on the icon and select Properties. Then select the Connections tab. Make sure you have a default profile that works and 'Always dial my default connection' is selected.

    VB Code:
    1. Private Declare Function InternetAutodialHangup Lib "wininet.dll" _
    2. (ByVal dwReserved As Long) As Long
    3.  
    4. Private Declare Function InternetAutodial Lib "wininet.dll" _
    5. (ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
    6.  
    7. Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1 '<-- makes user hit enter on connect dialog
    8. Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2 '<--- does it auto
    9.  
    10.  
    11. 'To automatically start dialling Internet connect
    12.  
    13. If InternetAutodial(INTERNET_AUTODIAL_FORCE_UNATTENDED, 0) Then
    14. DoEvents
    15. Else
    16. MsgBox "Unable to connect to the Internet", vbCritical
    17. Exit Sub
    18. End If
    19.  
    20. ' to dis-connect
    21.  
    22. If InternetAutodialHangup(0) Then
    23. DoEvents
    24. Else
    25. MsgBox "Unable to dis-connect from the Internet", vbCritical
    26. Exit Sub
    27. End If

  5. #5
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    It does help to ask the right question...

    First, If it is not dialing the modem, perhaps your modem is not on COM1. Try a different comport. For instance this will dial out on COM2

    DialNumber "767-8900", "COM2"

    To dial a DUN connectoid you can use the InternetDial Function.

    VB Code:
    1. Dim sConnection  As String
    2. Dim lConnection As Long
    3.  
    4. 'to dail out
    5. sConnection = "cswnet"
    6. Call InternetDial(Form1.hWnd, sConnection, INTERNET_DIAL_UNATTENDED, lConnection, 0)
    7.  
    8. 'Then to hangup to connection
    9.  
    10. If lConnection = 0 Then Exit Sub
    11. Call InternetHangUp(lConnection, 0)
    12. lConnection = 0
    13.  
    14.  
    15. 'Bas module
    16. Declare Function InternetHangUp Lib "wininet.dll" (ByVal dwConnection As Long, ByVal dwReserved As Long) As Long
    17. Declare Function InternetDial Lib "wininet.dll" (ByVal hwndParent As Long, ByVal lpszConnectoid As String, ByVal dwFlags As Long, dwConnection As Long, ByVal dwReserved As Long) As Long


    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

  6. #6
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    PS

    You'll need this.

    Private Const INTERNET_DIAL_UNATTENDED = &H8000


    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

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