|
-
Oct 9th, 2000, 10:37 AM
#1
Hi,
I'm using JMailer to send a simple e-mail but the user of my app won't have a permanent connection to the net. Is there some code any of you could suggest that will allow me to automaticly dial a DUN connection when the user clicks on the send button? (Preferably also giving the user a chance to disconnect after the e-mail has been sent as well.) Thanks,
Rhys
-
Oct 9th, 2000, 10:47 AM
#2
To automatically connect to the net:
Code:
Private Sub Command1_Click()
Dim X
'"ConnectionsName" is the name under the icon in Dial-up Networking
X = Shell("rundll32.exe rnaui.dll,RnaDial " & "ConnectionsName", 1)
DoEvents
'You can type in your password before the { below.
SendKeys "{enter}", True
DoEvents
End Sub
To disconnect:
Code:
Public Const RAS_MAXENTRYNAME As Integer = 256
Public Const RAS_MAXDEVICETYPE As Integer = 16
Public Const RAS_MAXDEVICENAME As Integer = 128
Public Const RAS_RASCONNSIZE As Integer = 412
Public Const ERROR_SUCCESS = 0&
Public Type RasEntryName
dwSize As Long
szEntryName(RAS_MAXENTRYNAME) As Byte
End Type
Public Type RasConn
dwSize As Long
hRasConn As Long
szEntryName(RAS_MAXENTRYNAME) As Byte
szDeviceType(RAS_MAXDEVICETYPE) As Byte
szDeviceName(RAS_MAXDEVICENAME) As Byte
End Type
Public Declare Function RasEnumConnections Lib _
"rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasConn As _
Any, lpcb As Long, lpcConnections As Long) As Long
Public Declare Function RasHangUp Lib "rasapi32.dll" Alias _
"RasHangUpA" (ByVal hRasConn As Long) As Long
Public gstrISPName As String
Public ReturnCode As Long
Procedure
Public Sub HangUp()
Dim i As Long
Dim lpRasConn(255) As RasConn
Dim lpcb As Long
Dim lpcConnections As Long
Dim hRasConn As Long
lpRasConn(0).dwSize = RAS_RASCONNSIZE
lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
lpcConnections = 0
ReturnCode = RasEnumConnections(lpRasConn(0), lpcb, _
lpcConnections)
If ReturnCode = ERROR_SUCCESS Then
For i = 0 To lpcConnections - 1
If Trim(ByteToString(lpRasConn(i).szEntryName)) _
= Trim(gstrISPName) Then
hRasConn = lpRasConn(i).hRasConn
ReturnCode = RasHangUp(ByVal hRasConn)
End If
Next i
End If
End Sub
Public Function ByteToString(bytString() As Byte) As String
Dim i As Integer
ByteToString = ""
i = 0
While bytString(i) = 0&
ByteToString = ByteToString & Chr(bytString(i))
i = i + 1
Wend
End Function
Usage
Call HangUp
-
Oct 9th, 2000, 11:02 AM
#3
I can connect with that code so thanks for that, but when I try and disconnect I get the error 'User-defined type not defined'. It doesn't like this line: lpRasConn(255) As RasConn.
I could might have put something where it dosn't belong. As you may have gathered I'm quite new to API and stuff like that! Any suggestions?
Rhys
-
Oct 9th, 2000, 11:14 AM
#4
Frenzied Member
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 9th, 2000, 11:22 AM
#5
ummm, don't been to be stupid - but what's meant to go where that smiley is?
-
Oct 9th, 2000, 11:30 AM
#6
Frenzied Member
-
Oct 9th, 2000, 11:43 AM
#7
Ok, I think I must be doing something wrong. Out of the following code, whaht goes in a module and what goes into the form code ??? This is driving me insane!
Rhys
P.S
I also can't understand the <code> tags as well so forgive me for the unformatted code!
Const RAS_MAXENTRYNAME = 256
Const RAS_MAXDEVICETYPE = 16
Const RAS_MAXDEVICENAME = 128
Const RAS_RASCONNSIZE = 412
Private Type RasEntryName
dwSize As Long
szEntryName(RAS_MAXENTRYNAME) As Byte
End Type
Private Type RasConn
dwSize As Long
hRasConn As Long
szEntryName(RAS_MAXENTRYNAME) As Byte
szDeviceType(RAS_MAXDEVICETYPE) As Byte
szDeviceName(RAS_MAXDEVICENAME) As Byte
End Type
Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasConn As Any, lpcb As Long, lpcConnections As Long) As Long
Private Declare Function RasHangUp Lib "rasapi32.dll" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long
Sub HangUp()
Dim i As Long
Dim lpRasConn(255) As RasConn
Dim lpcb As Long
Dim lpcConnections As Long
Dim hRasConn As Long
lpRasConn(0).dwSize = RAS_RASCONNSIZE
lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
lpcConnections = 0
ReturnCode = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections)
If ReturnCode = ERROR_SUCCESS Then
For i = 0 To lpcConnections - 1
If Trim(CStr(lpRasConn(i).szEntryName)) = Trim(gstrispname) Then
hRasConn = lpRasConn(i).hRasConn
ReturnCode = RasHangUp(ByVal hRasConn)
End If
Next i
End If
End Sub
-
Oct 9th, 2000, 11:51 AM
#8
Frenzied Member
Looking at all the private statement I would say it has to be placed in a module.
Did you use
Code:
Private Sub Command1_click()
Call HangUp
End Sub
in your form?
I can't test it because I have cable.
Anyway, for the formatting use
[code] My code goed here [/code]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Oct 9th, 2000, 01:37 PM
#9
I tried putting all the code into a module and calling the 'HangUp' sub but I still get the same error. I've tried putting the HangUp sub in the form code and calling it from there, but again, I get the same error. Is there anyone with a dial-up networking connection that could try this?
Rhys
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
|