Results 1 to 2 of 2

Thread: establishing a dial up connection

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Location
    Tehran
    Posts
    3

    Lightbulb establishing a dial up connection

    Hi all,

    My problem is as below:

    When someone calls and connects to one of the modems that is connected to my computer I should dial an already defined dial up connection so that the new caller can connect to Internet through my computer.
    My problem is how to start the dial up cpnnection and how to make it start dialing. Just as one does manually.

    Thanx
    Mahmoud

  2. #2
    Si_the_geek
    Guest
    Here's an example from ALLApi.Net, they've got lots of useful bits for all the other functions (eg: disconnect RAS)
    VB Code:
    1. 'This program let you dial to your dial-up connections using whether
    2. 'the stored user name and password or  the ones you specifies
    3. '(It use RasDial for dialing)
    4.  
    5. 'You need a form with a list,2 textbox and a command button
    6.  
    7. Option Explicit
    8. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, ByVal pSrc As String, ByVal ByteLen As Long)
    9. Private Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (Destination As Any, ByVal Length As Long)
    10.  
    11. Const RAS95_MaxEntryName = 256
    12. Const RAS_MaxPhoneNumber = 128
    13. Const RAS_MaxCallbackNumber = RAS_MaxPhoneNumber
    14.  
    15. Const UNLEN = 256
    16. Const PWLEN = 256
    17. Const DNLEN = 12
    18. Private Type RASDIALPARAMS
    19.    dwSize As Long ' 1052
    20.    szEntryName(RAS95_MaxEntryName) As Byte
    21.    szPhoneNumber(RAS_MaxPhoneNumber) As Byte
    22.    szCallbackNumber(RAS_MaxCallbackNumber) As Byte
    23.    szUserName(UNLEN) As Byte
    24.    szPassword(PWLEN) As Byte
    25.    szDomain(DNLEN) As Byte
    26. End Type
    27.  
    28. Private Type RASENTRYNAME95
    29.     'set dwsize to 264
    30.     dwSize As Long
    31.     szEntryName(RAS95_MaxEntryName) As Byte
    32. End Type
    33.  
    34. Private Declare Function RasDial Lib "rasapi32.dll" Alias "RasDialA" (ByVal lprasdialextensions As Long, ByVal lpcstr As String, ByRef lprasdialparamsa As RASDIALPARAMS, ByVal dword As Long, lpvoid As Any, ByRef lphrasconn As Long) As Long
    35. Private Declare Function RasEnumEntries Lib "rasapi32.dll" Alias "RasEnumEntriesA" (ByVal reserved As String, ByVal lpszPhonebook As String, lprasentryname As Any, lpcb As Long, lpcEntries As Long) As Long
    36. Private Declare Function RasGetEntryDialParams Lib "rasapi32.dll" Alias "RasGetEntryDialParamsA" (ByVal lpcstr As String, ByRef lprasdialparamsa As RASDIALPARAMS, ByRef lpbool As Long) As Long
    37.  
    38. Private Function Dial(ByVal Connection As String, ByVal UserName As String, ByVal Password As String) As Boolean
    39.     Dim rp As RASDIALPARAMS, h As Long, resp As Long
    40.     rp.dwSize = Len(rp) + 6
    41.     ChangeBytes Connection, rp.szEntryName
    42.     ChangeBytes "", rp.szPhoneNumber 'Phone number stored for the connection
    43.     ChangeBytes "*", rp.szCallbackNumber 'Callback number stored for the connection
    44.     ChangeBytes UserName, rp.szUserName
    45.     ChangeBytes Password, rp.szPassword
    46.     ChangeBytes "*", rp.szDomain 'Domain stored for the connection
    47.     'Dial
    48.     resp = RasDial(ByVal 0, ByVal 0, rp, 0, ByVal 0, h)   'AddressOf RasDialFunc
    49.     Dial = (resp = 0)
    50. End Function
    51.  
    52. Private Function ChangeToStringUni(Bytes() As Byte) As String
    53.     'Changes an byte array  to a Visual Basic unicode string
    54.     Dim temp As String
    55.     temp = StrConv(Bytes, vbUnicode)
    56.     ChangeToStringUni = Left(temp, InStr(temp, Chr(0)) - 1)
    57. End Function
    58.  
    59. Private Function ChangeBytes(ByVal str As String, Bytes() As Byte) As Boolean
    60.     'Changes a Visual Basic unicode string to an byte array
    61.     'Returns True if it truncates str
    62.     Dim lenBs As Long 'length of the byte array
    63.     Dim lenStr As Long 'length of the string
    64.     lenBs = UBound(Bytes) - LBound(Bytes)
    65.     lenStr = LenB(StrConv(str, vbFromUnicode))
    66.     If lenBs > lenStr Then
    67.         CopyMemory Bytes(0), str, lenStr
    68.         ZeroMemory Bytes(lenStr), lenBs - lenStr
    69.     ElseIf lenBs = lenStr Then
    70.         CopyMemory Bytes(0), str, lenStr
    71.     Else
    72.         CopyMemory Bytes(0), str, lenBs 'Queda truncado
    73.         ChangeBytes = True
    74.     End If
    75. End Function
    76.  
    77. Private Sub Command1_Click()
    78.     Dial List1.Text, Text1, Text2
    79. End Sub
    80.  
    81.  
    82. Private Sub List1_Click()
    83.     Dim rdp As RASDIALPARAMS, t As Long
    84.     rdp.dwSize = Len(rdp) + 6
    85.     ChangeBytes List1.Text, rdp.szEntryName
    86.     'Get User name and password for the connection
    87.     t = RasGetEntryDialParams(List1.Text, rdp, 0)
    88.     If t = 0 Then
    89.         Text1 = ChangeToStringUni(rdp.szUserName)
    90.         Text2 = ChangeToStringUni(rdp.szPassword)
    91.     End If
    92. End Sub
    93.  
    94. Private Sub Form_Load()
    95.     'example created by Daniel Kaufmann ([email protected])
    96.     'load the connections
    97.     Text2.PasswordChar = "*"
    98.     Command1.Caption = "Dial"
    99.     Dim s As Long, l As Long, ln As Long, a$
    100.     ReDim r(255) As RASENTRYNAME95
    101.    
    102.     r(0).dwSize = 264
    103.     s = 256 * r(0).dwSize
    104.     l = RasEnumEntries(vbNullString, vbNullString, r(0), s, ln)
    105.     For l = 0 To ln - 1
    106.         a$ = StrConv(r(l).szEntryName(), vbUnicode)
    107.         List1.AddItem Left$(a$, InStr(a$, Chr$(0)) - 1)
    108.     Next
    109.     If List1.ListCount > 0 Then
    110.         List1.ListIndex = 0
    111.         List1_Click
    112.     End If
    113. End Sub

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