CrAzY hOuSe
Locos por la programación
Conexiones RAS a Internet.
.net

Syndication

Realiza una conexión RAS (Acceso Telefónico a Redes) introduciendo los datos por el usuario.

api97

El código.... Tienes que crear 3 TextBox (Text1, Text2 y Text3) y 2 Command_Button (Command1 y Command2).

Option Explicit
Private Type RASDIALPARAMS
    dwSize As Long
    szEntryName As String * 257
    szPhoneNumber As String * 129
    szCallbackNumber As String * 129
    szUserName As String * 257
    szPassword As String * 257
    szDomain As String * 16
    filler As String * 16
End Type
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal miliseg As Long)
Private Declare Sub strcpyn Lib "kernel32.dll" Alias "lstrcpynA" (ByVal a As String, ByVal de As String, ByVal N As Long)
Private Declare Function strlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal texto As String) As Long
Private Declare Function RasHangUp Lib "rasapi32.dll" Alias "RasHangUpA" (ByVal handle As Long) As Integer
Private Declare Function RasDial Lib "rasapi32.dll" Alias "RasDialA" (ByVal p1 As Long, ByVal p2 As Long, _
             rd As RASDIALPARAMS, ByVal p4 As Long, ByVal p5 As Long, handle As Long) As Integer
Private Declare Sub RasGetErrorString Lib "rasapi32.dll" Alias "RasGetErrorStringA" (ByVal nmumer As Long, _
             ByVal buffer As String, ByVal sizebuf As Long)
'# # # # # # # # # # # # # # # # # #
Dim hDial As Long 'handle de la conexion
'# # # # # # # # # # # # # # # # # #

Function Conectar(Entry As String, User As String, Pass As String) As Integer
    Dim Rdp As RASDIALPARAMS
    Rdp.dwSize = 1052
    strcpyn Rdp.szEntryName, Entry + Chr$(0), 256
    strcpyn Rdp.szPhoneNumber, Chr$(0), 128
    strcpyn Rdp.szCallbackNumber, Chr$(0), 128
    strcpyn Rdp.szUserName, User + Chr$(0), 256
    strcpyn Rdp.szPassword, Pass + Chr$(0), 256
    strcpyn Rdp.szDomain, Chr$(0), 15
    Conectar = RasDial(0, 0, Rdp, 0, 0, hDial)
End Function
Function Desconectar() As Long
    Dim N As Long
    If hDial <> 0 Then
        N = RasHangUp(hDial)
        If N = 0 Then
            hDial = 0
            Sleep (3000)
        End If
    End If
    Desconectar = N
End Function
Function TextoError(Num As Long) As String
    ' Formatea la cadena de texto que muestra el error ocurrido
    Dim Txt As String * 128
    Txt = Chr$(0)
    RasGetErrorString Num, Txt, 127
    TextoError = Left$(Txt, strlen(Txt))
End Function
Private Sub Command1_Click()
    ' Botón Conexión
    Dim N As Long
    If hDial <> 0 Then
        Label1 = "Ya estaba conectado"
        Exit Sub
    End If
    N = Conectar(Text1, Text2, Text3)
    If N = 0 Then
        Label1 = "Conectado"
    Else
        Label1 = TextoError(N)
    End If
End Sub
Private Sub Command2_Click()
    ' Botón DesConexión
    Dim N As Long
    If hDial = 0 Then
        Label1 = "No estaba conectado"
        Exit Sub
    End If
    N = Desconectar
    If N = 0 Then
        Label1 = "Desconectado"
    Else
        Label1 = TextoError(N)
    End If
End Sub

Posted lun, jul 10 2000 19:47 by Maverick
Filed under: ,

Add a Comment

(optional)  
(optional)
(required)  
Remember Me?
MavericK
Powered by Community Server (Non-Commercial Edition), by Telligent Systems