Click to See Complete Forum and Search --> : how to use rasapi32
Mojik
Aug 6th, 2000, 01:59 PM
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 :)
QWERTY
Aug 7th, 2000, 11:24 AM
'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
MartinRobins
Aug 7th, 2000, 02:00 PM
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.
Mojik
Aug 7th, 2000, 06:37 PM
Thanx 4 your help :)
zdocteur
Aug 11th, 2000, 06:34 AM
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
gwdash
Aug 12th, 2000, 08:50 PM
Why not use the MSComm control, it might be simpler, might not.
zdocteur
Aug 12th, 2000, 11:08 PM
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
gwdash
Aug 13th, 2000, 10:45 AM
There's something with the Microsoft Speach SDK, no that's just speack recognition over the phone, anyway, you could try that
burner
Aug 14th, 2000, 02:55 PM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.