Results 1 to 9 of 9

Thread: how to use rasapi32

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    8

    Post

    I need to dialup/hangup from my vb6 app, I think this can be done with rasapi32, but I new to API and I don't know how to use it. The two functions are RasDial and RasHangUp ...

    Please help

    Thanx a lot


  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    how about...

    Code:
    'Make a new project. Add a module. To the form add a text box, a combo box and a command button.
    
    'Code:
    'Add this code to the module:
    
    Option Explicit
    Declare Function WriteFile& Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite&, lpNumberOfBytesWritten&, ByVal lpOverlapped&)
    Declare Function CreateFile& Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName$, ByVal dwDesiredAccess&, ByVal dwShareMode&, ByVal lpSecurityAttributes&, ByVal dwCreationDisposition&, ByVal dwFlagsAndAttributes&, ByVal hTemplateFile&)
    Declare Function CloseHandle& Lib "kernel32" (ByVal hObject&)
    Declare Function FlushFileBuffers& Lib "kernel32" (ByVal hFile&)
    Public Const WAITSECONDS = 4
    Public Const ID_CANCEL = 2
    Public Const MB_OKCANCEL = 1
    Public Const MB_ICONSTOP = 16, MB_ICONINFORMATION = 64
    
    Function DialNumber(PhoneNumber, CommPort As String)
        Dim Msg As String, MsgBoxType As Integer, MsgBoxTitle As String
        Dim bModemCommand(256) As Byte, ModemCommand As String
        Dim OpenPort As Long
        Dim RetVal As Long, RetBytes As Long, i As Integer
        Dim StartTime
        ' Ask the user to pick up the phone.
        Msg = "Please pickup the phone and choose OK to dial " & PhoneNumber
        MsgBoxType = MB_ICONINFORMATION + MB_OKCANCEL
        MsgBoxTitle = "Dial Number"
        If MsgBox(Msg, MsgBoxType, MsgBoxTitle) = ID_CANCEL Then
            Exit Function
        End If
        ' Open the communications port for read/write (&HC0000000).
        ' Must specify existing file (3).
        OpenPort = CreateFile(CommPort, &HC0000000, 0, 0, 3, 0, 0)
        If OpenPort = -1 Then
            Msg = "Unable to open communication port " & CommPort
            GoTo Err_DialNumber
        End If
        ' Send the telephone number to the modem.
        ModemCommand = "ATDT" & PhoneNumber & vbCrLf
        ' Pack the string in a Byte array.
        For i = 0 To Len(ModemCommand) - 1
            bModemCommand(i) = Asc(Mid(ModemCommand, i + 1, 1))
        Next
        ' Write the string to the Com port.
        RetVal = WriteFile(OpenPort, bModemCommand(0), Len(ModemCommand), RetBytes, 0)
        If RetVal = 0 Then
            Msg = "Unable to dial number " & PhoneNumber
            GoTo Err_DialNumber
        End If
        ' Flush the buffer to make sure it actually wrote
        RetVal = FlushFileBuffers(OpenPort)
        ' Wait WAITSECONDS seconds for the phone to dial.
        StartTime = Timer
        While Timer < StartTime + WAITSECONDS
            DoEvents
        Wend
        ' Reset the modem and take it off line.
        ModemCommand = "ATH0" & vbCrLf
        ' Pack the byte array again.
        For i = 0 To Len(ModemCommand) - 1
            bModemCommand(i) = Asc(Mid(ModemCommand, i + 1, 1))
        Next
        RetVal = WriteFile(OpenPort, bModemCommand(0), Len(ModemCommand), RetBytes, 0)
        'Flush the buffer again.
        RetVal = FlushFileBuffers(OpenPort)
        ' Close the communications port.
        RetVal = CloseHandle(OpenPort)
        Exit Function
    
    Err_DialNumber:     'This is not an On Error routine.
        Msg = Msg & vbCr & vbCr & "Make sure no other devices are using Com port " & CommPort
        MsgBoxType = MB_ICONSTOP
    
        MsgBoxTitle = "Dial Number Error"
        MsgBox Msg, MsgBoxType, MsgBoxTitle
    End Function
    
    'Add this code to the form's load procedure:
    
    Private Sub Form_Load()
        With Combo1
            .AddItem "COM1"
            .AddItem "COM2"
            .AddItem "COM3"
            .AddItem "COM4"
        End With
    End Sub
    
    'Add this code to the command button:
    
    Private Sub Command1_Click()
        Temp = DialNumber(Text1.Text, Combo1.Text)
    End Sub
    DIDN'T TEST IT!!!!!

    Post #507

  3. #3
    New Member
    Join Date
    Aug 2000
    Location
    Leicestershire, ENGLAND
    Posts
    2

    Re: how about...

    Using the RAS API calls, you can create connections to other networks and automatically dial-up and connect. This API is used behind the "Dial Up Networking" subsystem.

    The calls available within RAS do not include a simple dialer function and therefore the code snippet above is the best starting point.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    8
    Thanx 4 your help

  5. #5
    New Member
    Join Date
    May 2000
    Posts
    15
    to QWERTY,

    Re the above code

    i tried to dial the phone through the above code and when
    prompted to pick up th e phone to dial the number nothing
    happened.

    my modem is on COM3

    any idea what could B wrong ??

    another question.
    anyone knows how 2 connect the modem 2 the sound card i.e.
    to send and recieve voice through the computer's speakers &
    mic. to the modem. is there any certain API or add-in to do this job??

    thanx in advance

    zdocteur

  6. #6
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    Why not use the MSComm control, it might be simpler, might not.
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  7. #7
    New Member
    Join Date
    May 2000
    Posts
    15
    the MSComm control is good enough to dial up and hang up,
    but i need to connect the modem to the computer's speakers and mic.

    is there any VB control to access these devices and connect them to the modem ?!

    regards

    zdocteur

  8. #8
    Fanatic Member gwdash's Avatar
    Join Date
    Aug 2000
    Location
    Minnesota
    Posts
    666
    There's something with the Microsoft Speach SDK, no that's just speack recognition over the phone, anyway, you could try that
    GWDASH
    [b]VB6, Perl, ASP, HTML, JavaScript, VBScript, SQL, C, C++, Linux , Java, PHP, MySQL, XML[b]

  9. #9
    New Member
    Join Date
    Aug 2000
    Location
    Bethany, IL
    Posts
    3

    rasdial.ocx

    There is a great active x control made by Rod Hewitt called
    RasDial.ocx It works well for connecting and
    disconnecting, and it can also create/edit/delete phonebook
    entries. The unregistered free version will
    connect/disconnect, and the registered version ($25 US)
    will do the phonebook stuff. http://www.coolstf.com


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