Results 1 to 9 of 9

Thread: Automaticly Dialing a DUN connection??

  1. #1
    Guest

    Question

    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

  2. #2
    Guest
    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

  3. #3
    Guest
    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

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Here are the tips you need:

    http://kpdteam.tripod.com/tips/tips4.htm
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Guest
    ummm, don't been to be stupid - but what's meant to go where that smiley is?

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I don't see no smiley man!? I am crazy or just drunk?

    Anyway:

    = : )
    = ; )
    = : rolleyes :
    = : confused :
    = : D
    = : mad :


    Removes the spaces between the :

    http://209.207.250.147/index.php?action=showsmilies
    look there for all the smileys.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7
    Guest
    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

  8. #8
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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.

  9. #9
    Guest
    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
  •  



Click Here to Expand Forum to Full Width