|
-
Sep 16th, 2001, 10:22 PM
#1
Thread Starter
Frenzied Member
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?
-
Sep 16th, 2001, 11:19 PM
#2
Frenzied Member
This is a Form and Module that shows how to open a com port and dial out.
Form1
VB Code:
Option Explicit
Private Sub Form_Load()
DialNumber "767-8900", "COM1"
End Sub
Private Sub DialNumber(sPhoneNumber, sCommPort As String)
Dim sMsg As String
Dim bModemCommand() As Byte, sCommand As String
Dim lOpenPort As Long
Dim lRet As Long, lRetBytes As Long, i As Integer
If MsgBox("Please pickup the phone and choose OK to dial " & sPhoneNumber, vbOKCancel, App.Title) = vbCancel Then
Exit Sub
End If
lOpenPort = CreateFile(sCommPort, &HC0000000, 0, 0, OPEN_ALWAYS, 0, 0)
If lOpenPort = -1 Then
sMsg = "Unable to open communication port " & sCommPort
GoTo Err_DialNumber
End If
sCommand = "ATDT" & sPhoneNumber & vbCrLf
ReDim bModemCommand(Len(sCommand))
For i = 0 To Len(sCommand) - 1
bModemCommand(i) = Asc(Mid$(sCommand, i + 1, 1))
Next
lRet = WriteFile(lOpenPort, bModemCommand(0), Len(sCommand), lRetBytes, 0)
If lRet = 0 Then
sMsg = "Unable to dial number " & sPhoneNumber
GoTo Err_DialNumber
End If
lRet = FlushFileBuffers(lOpenPort)
MsgBox "Click OK when the phone finishes dialing. "
sCommand = "ATH0" & vbCrLf
ReDim bModemCommand(Len(sCommand))
For i = 0 To Len(sCommand) - 1
bModemCommand(i) = Asc(Mid$(sCommand, i + 1, 1))
Next
lRet = WriteFile(lOpenPort, bModemCommand(0), Len(sCommand), lRetBytes, 0)
lRet = FlushFileBuffers(lOpenPort)
lRet = CloseHandle(lOpenPort)
Exit Sub
Err_DialNumber:
MsgBox sMsg & vbCr & vbCr & "Make sure no other devices are using Com port " & sCommPort
End Sub
Module
VB Code:
Option Explicit
Public Const OPEN_EXISTING = 3
Public Const OPEN_ALWAYS = 4
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
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
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
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.
-
Sep 17th, 2001, 07:07 PM
#3
Thread Starter
Frenzied Member
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?
-
Sep 17th, 2001, 07:22 PM
#4
Fanatic Member
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:
Private Declare Function InternetAutodialHangup Lib "wininet.dll" _
(ByVal dwReserved As Long) As Long
Private Declare Function InternetAutodial Lib "wininet.dll" _
(ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1 '<-- makes user hit enter on connect dialog
Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2 '<--- does it auto
'To automatically start dialling Internet connect
If InternetAutodial(INTERNET_AUTODIAL_FORCE_UNATTENDED, 0) Then
DoEvents
Else
MsgBox "Unable to connect to the Internet", vbCritical
Exit Sub
End If
' to dis-connect
If InternetAutodialHangup(0) Then
DoEvents
Else
MsgBox "Unable to dis-connect from the Internet", vbCritical
Exit Sub
End If
-
Sep 17th, 2001, 07:25 PM
#5
Frenzied Member
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:
Dim sConnection As String
Dim lConnection As Long
'to dail out
sConnection = "cswnet"
Call InternetDial(Form1.hWnd, sConnection, INTERNET_DIAL_UNATTENDED, lConnection, 0)
'Then to hangup to connection
If lConnection = 0 Then Exit Sub
Call InternetHangUp(lConnection, 0)
lConnection = 0
'Bas module
Declare Function InternetHangUp Lib "wininet.dll" (ByVal dwConnection As Long, ByVal dwReserved As Long) As Long
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.
-
Sep 17th, 2001, 07:27 PM
#6
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|