home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbrasa / vbrasapi.bas < prev   
Encoding:
BASIC Source File  |  1995-01-10  |  23.4 KB  |  576 lines

  1. 'Description
  2.     'This module provides a simple RAS API to VB applications, based on RASAPI16.DLL.
  3.     'All subs beginning with VBRAS may be used externally.
  4.     'VBRAS_DIAL_INFO_TYPE is the only type to be used externally.
  5.     '
  6.     'Written by Adam Ziegler CIS:72147,2221
  7.  
  8. 'Clean Living <g>
  9. Option Explicit
  10.  
  11. Const mnVBRAS_MAX_CONNECTIONS = 3 'Max connections VBRAS should support
  12.  
  13. 'For use with VBRASDial
  14. Type VBRAS_DIAL_INFO_TYPE
  15.     PhoneBook As String         'full path, defaults to standard if = ""
  16.     entryname As String         'entry to dial. If = "", phone number must be provided
  17.     Username As String          'username for auth. If "" will attempt to use logged-on user
  18.     Password As String          'if blank, will prompt
  19.     Domain As String            'Domain for auth. If "" will use from phonebook, if * will use from server
  20.     PhoneNumber As String       'Will override phonebook entry
  21.     CallbackNumber As String    'Only valid if server set up for user-specified callback
  22. End Type
  23.  
  24. 'Original User Information Length Constants
  25. Const UNLEN = 20    'Username
  26. Const PWLEN = 14    'Password
  27. Const DNLEN = 15    'Domain
  28. Const UNLENPlus1 = UNLEN + 1
  29. Const PWLENPlus1 = PWLEN + 1
  30. Const DNLENPlus1 = DNLEN + 1
  31.  
  32. 'Original RASAPI16.DLL Constants
  33. Const RASCS_DONE = &H2000
  34. Const RASCS_PAUSED = &H1000
  35. Const RAS_MaxCallbackNumber = 48
  36. Const RAS_MaxDeviceName = 32
  37. Const RAS_MaxDeviceType = 16
  38. Const RAS_MaxEntryName = 20
  39. Const RAS_MaxParamKey = 32
  40. Const RAS_MaxParamValue = 128
  41. Const RAS_MaxPhoneNumber = 128
  42.  
  43. Const RAS_MaxCallbackNumberPlus1 = RAS_MaxCallbackNumber + 1
  44. Const RAS_MaxDeviceNamePlus1 = RAS_MaxDeviceName + 1
  45. Const RAS_MaxDeviceTypePlus1 = RAS_MaxDeviceType + 1
  46. Const RAS_MaxEntryNamePlus1 = RAS_MaxEntryName + 1
  47. Const RAS_MaxParamKeyPlus1 = RAS_MaxParamKey + 1
  48. Const RAS_MaxParamValuePlus1 = RAS_MaxParamValue + 1
  49. Const RAS_MaxPhoneNumberPlus1 = RAS_MaxPhoneNumber + 1
  50.  
  51. 'Declare RASAPI16.DLL Structures
  52. Type RASCONN
  53.     dwSize As Long                              ' Size in bytes of RASCONN Structure (30)
  54.     hrasconn As Long                            ' handle to connection
  55.     szEntryName As String * RAS_MaxEntryNamePlus1  'name or "" followed by phone #
  56.     szFiller As String * 1                      'must end on word (2-byte) boundary
  57. End Type
  58.  
  59. 'Equiv of _RASCONNSTATE enumerated type
  60.     Global Const RAS_OpenPort = 0
  61.     Global Const RAS_PortOpened = 1
  62.     Global Const RAS_ConnectDevice = 2
  63.     Global Const RAS_DeviceConnected = 3
  64.     Global Const RAS_AllDevicesConnected = 4
  65.     Global Const RAS_Authenticate = 5
  66.     Global Const RAS_AuthNotify = 6
  67.     Global Const RAS_AuthRetry = 7
  68.     Global Const RAS_AuthCallback = 8
  69.     Global Const RAS_AuthChangePassword = 9
  70.     Global Const RAS_AuthProject = 10
  71.     Global Const RAS_AuthLinkSpeed = 11
  72.     Global Const RAS_AuthAck = 12
  73.     Global Const RAS_ReAuthenticate = 13
  74.     Global Const RAS_Authenticated = 14
  75.     Global Const RAS_PrepareForCallback = 15
  76.     Global Const RAS_WaitForModemReset = 16
  77.     Global Const RAS_WaitForCallback = 17
  78.     Global Const RAS_Interactive = RASCS_PAUSED
  79.     Global Const RAS_RetryAuthentication = RASCS_PAUSED + 1
  80.     Global Const RAS_CallbackSetByCaller = RASCS_PAUSED + 2
  81.     Global Const RAS_PasswordExpired = RASCS_PAUSED + 3
  82.     Global Const RAS_Connected = RASCS_DONE
  83.     Global Const RAS_Disconnected = RASCS_DONE + 1
  84. 'End _RASCONNSTATE declarations
  85.  
  86. Type RASCONNSTATUS
  87.     dwSize As Long              ' size of struct in bytes (60)
  88.     rasconnstate As Integer     ' one of RASCONNSTATE enum types
  89.     dwError As Long             ' reason for fail if non-zero
  90.     szDeviceType    As String * RAS_MaxDeviceTypePlus1  'current dev type
  91.     szDevicename    As String * RAS_MaxDeviceNamePlus1  'current dev name
  92. End Type
  93.  
  94. Type RASDIALPARAMS
  95.     dwSize As Long  ' size of struct (256, calculates to 255)
  96.     szEntryName As String * RAS_MaxEntryNamePlus1
  97.     szPhoneNumber As String * RAS_MaxPhoneNumberPlus1
  98.     szCallbackNumber As String * RAS_MaxCallbackNumberPlus1
  99.     szUserName As String * UNLENPlus1
  100.     szPassword As String * PWLENPlus1
  101.     szDomain As String * DNLENPlus1
  102.     szFiller As String * 1
  103. End Type
  104.  
  105. Type RASENTRYNAME
  106.    dwSize As Long   ' size of struct (26)
  107.    szEntryName As String * RAS_MaxEntryNamePlus1
  108.    szFiller As String * 1
  109. End Type
  110.  
  111. 'Declare RASAPI16.DLL external functions
  112. Declare Function RASDIAL& Lib "RASAPI16.DLL" (reserved As Any, lpszPhonebookPath As Any, lprasdialparams As RASDIALPARAMS, reserved2 As Any, ByVal hwndNotifier As Integer, lphrasconn As Long)
  113.     'LPTSTR             reserved;           /* reserved; must be set to NULL*/
  114.     'LPTSTR             lpszPhonebookPath;  /* full pathname to Phone Book file*/
  115.     'LPRASDIALPARAMS    lpRasDialParams;    /* points to calling parameters*/
  116.     'LPVOID             reserved2;          /* reserved; must be set to NULL*/
  117.     'HWND               hwndNotifier;       /* notification message for RasDial events*/
  118.     'LPHRASCONN         lphrasconn;         /* points to variable to receive connection handle*/
  119.  
  120. Declare Function RasEnumConnections& Lib "RASAPI16.DLL" (lprasconn As RASCONN, lpcb&, lpcConnections&)
  121.     'LPRASCONN          lprasconn;          /* buffer to receive connections data */
  122.     'LPDWORD            lpcb;               /* size in bytes of buffer */
  123.     'LPDWORD            lpcConnections;     /* number of connections written to buffer */
  124.  
  125. 'Following function is not currently used by RASAPIVB
  126. 'Declare Function RasEnumEntries& Lib "RASAPI16.DLL" (reserved As Any, lpszPhonebookPath As Any, lprasentryname As RASENTRYNAME, lpcb As Long, lpcEntries As Long)
  127.     'LPTSTR             reserved;           /* reserved; must be NULL */
  128.     'LPTSTR             lpszPhonebookPath;  /* full path to Phone Book file */
  129.     'LPRASENTRYNAME     lprasentryname;     /* buffer to receive Phone Book entries */
  130.     'LPDWORD            lpcb;               /* size in bytes of buffer */
  131.     'LPDWORD            lpcEntries;         /* number of entries written to buffer */
  132.  
  133. Declare Function RasGetConnectStatus& Lib "RASAPI16.DLL" (ByVal hrasconn&, lprasconnstatus As RASCONNSTATUS)
  134.     'HRASCONN           hrasconn;           /* handle to Remote Access connection of interest */
  135.     'LPRASCONNSTATUS    lprasconnstatus;    /* buffer to receive status data */
  136.  
  137.  
  138. Declare Function RasGetErrorString& Lib "RASAPI16.DLL" (ByVal uErrorCode%, ByVal lpszErrorString$, ByVal cBufSize&)
  139.     'UINT               uErrorCode;         /* error code to get string for */
  140.     'LPSTR              lpszErrorString;    /* buffer to hold error string */
  141.     'DWORD              cBufSize;           /* sizeof buffer */
  142.  
  143. Declare Function RASHangUp& Lib "RASAPI16.DLL" (ByVal hrasconn As Long)
  144.     'HRASCONN           hrasconn;           /* handle to the Remote Access connection to hang up */
  145.  
  146.  
  147. 'Function needed to trap messages with MessageBlaster VBX
  148. Declare Function RegisterWindowMessage% Lib "user" (ByVal lpszMessage As String)
  149.  
  150. 'Error contants from RASERROR.H
  151. Global Const ERROR_INVALID_HANDLE = 6
  152. Global Const ERROR_NOT_ENOUGH_MEMORY = 8
  153. Global Const RASBASE = 600
  154. Global Const SUCCESS = 0
  155. Global Const PENDING = (RASBASE + 0)
  156. Global Const ERROR_INVALID_PORT_HANDLE = (RASBASE + 1)
  157. Global Const ERROR_PORT_ALREADY_OPEN = (RASBASE + 2)
  158. Global Const ERROR_BUFFER_TOO_SMALL = (RASBASE + 3)
  159. Global Const ERROR_WRONG_INFO_SPECIFIED = (RASBASE + 4)
  160. Global Const ERROR_CANNOT_SET_PORT_INFO = (RASBASE + 5)
  161. Global Const ERROR_PORT_NOT_CONNECTED = (RASBASE + 6)
  162. Global Const ERROR_EVENT_INVALID = (RASBASE + 7)
  163. Global Const ERROR_DEVICE_DOES_NOT_EXIST = (RASBASE + 8)
  164. Global Const ERROR_DEVICETYPE_DOES_NOT_EXIST = (RASBASE + 9)
  165. Global Const ERROR_INVALID_BUFFER = (RASBASE + 10)
  166. Global Const ERROR_ROUTE_NOT_AVAILABLE = (RASBASE + 11)
  167. Global Const ERROR_ROUTE_NOT_ALLOCATED = (RASBASE + 12)
  168. Global Const ERROR_INVALID_COMPRESSION_SPECIFIED = (RASBASE + 13)
  169. Global Const ERROR_OUT_OF_BUFFERS = (RASBASE + 14)
  170. Global Const ERROR_PORT_NOT_FOUND = (RASBASE + 15)
  171. Global Const ERROR_ASYNC_REQUEST_PENDING = (RASBASE + 16)
  172. Global Const ERROR_ALREADY_DISCONNECTING = (RASBASE + 17)
  173. Global Const ERROR_PORT_NOT_OPEN = (RASBASE + 18)
  174. Global Const ERROR_PORT_DISCONNECTED = (RASBASE + 19)
  175. Global Const ERROR_NO_ENDPOINTS = (RASBASE + 20)
  176. Global Const ERROR_CANNOT_OPEN_PHONEBOOK = (RASBASE + 21)
  177. Global Const ERROR_CANNOT_LOAD_PHONEBOOK = (RASBASE + 22)
  178. Global Const ERROR_CANNOT_FIND_PHONEBOOK_ENTRY = (RASBASE + 23)
  179. Global Const ERROR_CANNOT_WRITE_PHONEBOOK = (RASBASE + 24)
  180. Global Const ERROR_CORRUPT_PHONEBOOK = (RASBASE + 25)
  181. Global Const ERROR_CANNOT_LOAD_STRING = (RASBASE + 26)
  182. Global Const ERROR_KEY_NOT_FOUND = (RASBASE + 27)
  183. Global Const ERROR_DISCONNECTION = (RASBASE + 28)
  184. Global Const ERROR_REMOTE_DISCONNECTION = (RASBASE + 29)
  185. Global Const ERROR_HARDWARE_FAILURE = (RASBASE + 30)
  186. Global Const ERROR_USER_DISCONNECTION = (RASBASE + 31)
  187. Global Const ERROR_INVALID_SIZE = (RASBASE + 32)
  188. Global Const ERROR_PORT_NOT_AVAILABLE = (RASBASE + 33)
  189. Global Const ERROR_CANNOT_PROJECT_CLIENT = (RASBASE + 34)
  190. Global Const ERROR_UNKNOWN = (RASBASE + 35)
  191. Global Const ERROR_WRONG_DEVICE_ATTACHED = (RASBASE + 36)
  192. Global Const ERROR_BAD_STRING = (RASBASE + 37)
  193. Global Const ERROR_REQUEST_TIMEOUT = (RASBASE + 38)
  194. Global Const ERROR_CANNOT_GET_LANA = (RASBASE + 39)
  195. Global Const ERROR_NETBIOS_ERROR = (RASBASE + 40)
  196. Global Const ERROR_SERVER_OUT_OF_RESOURCES = (RASBASE + 41)
  197. Global Const ERROR_NAME_EXISTS_ON_NET = (RASBASE + 42)
  198. Global Const ERROR_SERVER_GENERAL_NET_FAILURE = (RASBASE + 43)
  199. Global Const WARNING_MSG_ALIAS_NOT_ADDED = (RASBASE + 44)
  200. Global Const ERROR_AUTH_INTERNAL = (RASBASE + 45)
  201. Global Const ERROR_RESTRICTED_LOGON_HOURS = (RASBASE + 46)
  202. Global Const ERROR_ACCT_DISABLED = (RASBASE + 47)
  203. Global Const ERROR_PASSWD_EXPIRED = (RASBASE + 48)
  204. Global Const ERROR_NO_DIALIN_PERMISSION = (RASBASE + 49)
  205. Global Const ERROR_SERVER_NOT_RESPONDING = (RASBASE + 50)
  206. Global Const ERROR_FROM_DEVICE = (RASBASE + 51)
  207. Global Const ERROR_UNRECOGNIZED_RESPONSE = (RASBASE + 52)
  208. Global Const ERROR_MACRO_NOT_FOUND = (RASBASE + 53)
  209. Global Const ERROR_MACRO_NOT_DEFINED = (RASBASE + 54)
  210. Global Const ERROR_MESSAGE_MACRO_NOT_FOUND = (RASBASE + 55)
  211. Global Const ERROR_DEFAULTOFF_MACRO_NOT_FOUND = (RASBASE + 56)
  212. Global Const ERROR_FILE_COULD_NOT_BE_OPENED = (RASBASE + 57)
  213. Global Const ERROR_DEVICENAME_TOO_LONG = (RASBASE + 58)
  214. Global Const ERROR_DEVICENAME_NOT_FOUND = (RASBASE + 59)
  215. Global Const ERROR_NO_RESPONSES = (RASBASE + 60)
  216. Global Const ERROR_NO_COMMAND_FOUND = (RASBASE + 61)
  217. Global Const ERROR_WRONG_KEY_SPECIFIED = (RASBASE + 62)
  218. Global Const ERROR_UNKNOWN_DEVICE_TYPE = (RASBASE + 63)
  219. Global Const ERROR_ALLOCATING_MEMORY = (RASBASE + 64)
  220. Global Const ERROR_PORT_NOT_CONFIGURED = (RASBASE + 65)
  221. Global Const ERROR_DEVICE_NOT_READY = (RASBASE + 66)
  222. Global Const ERROR_READING_INI_FILE = (RASBASE + 67)
  223. Global Const ERROR_NO_CONNECTION = (RASBASE + 68)
  224. Global Const ERROR_BAD_USAGE_IN_INI_FILE = (RASBASE + 69)
  225. Global Const ERROR_READING_SECTIONNAME = (RASBASE + 70)
  226. Global Const ERROR_READING_DEVICETYPE = (RASBASE + 71)
  227. Global Const ERROR_READING_DEVICENAME = (RASBASE + 72)
  228. Global Const ERROR_READING_USAGE = (RASBASE + 73)
  229. Global Const ERROR_READING_MAXCONNECTBPS = (RASBASE + 74)
  230. Global Const ERROR_READING_MAXCARRIERBPS = (RASBASE + 75)
  231. Global Const ERROR_LINE_BUSY = (RASBASE + 76)
  232. Global Const ERROR_VOICE_ANSWER = (RASBASE + 77)
  233. Global Const ERROR_NO_ANSWER = (RASBASE + 78)
  234. Global Const ERROR_NO_CARRIER = (RASBASE + 79)
  235. Global Const ERROR_NO_DIALTONE = (RASBASE + 80)
  236. Global Const ERROR_IN_COMMAND = (RASBASE + 81)
  237. Global Const ERROR_WRITING_SECTIONNAME = (RASBASE + 82)
  238. Global Const ERROR_WRITING_DEVICETYPE = (RASBASE + 83)
  239. Global Const ERROR_WRITING_DEVICENAME = (RASBASE + 84)
  240. Global Const ERROR_WRITING_MAXCONNECTBPS = (RASBASE + 85)
  241. Global Const ERROR_WRITING_MAXCARRIERBPS = (RASBASE + 86)
  242. Global Const ERROR_WRITING_USAGE = (RASBASE + 87)
  243. Global Const ERROR_WRITING_DEFAULTOFF = (RASBASE + 88)
  244. Global Const ERROR_READING_DEFAULTOFF = (RASBASE + 89)
  245. Global Const ERROR_EMPTY_INI_FILE = (RASBASE + 90)
  246. Global Const ERROR_AUTHENTICATION_FAILURE = (RASBASE + 91)
  247. Global Const ERROR_PORT_OR_DEVICE = (RASBASE + 92)
  248. Global Const ERROR_NOT_BINARY_MACRO = (RASBASE + 93)
  249. Global Const ERROR_DCB_NOT_FOUND = (RASBASE + 94)
  250. Global Const ERROR_STATE_MACHINES_NOT_STARTED = (RASBASE + 95)
  251. Global Const ERROR_STATE_MACHINES_ALREADY_STARTED = (RASBASE + 96)
  252. Global Const ERROR_PARTIAL_RESPONSE_LOOPING = (RASBASE + 97)
  253. Global Const ERROR_UNKNOWN_RESPONSE_KEY = (RASBASE + 98)
  254. Global Const ERROR_RECV_BUF_FULL = (RASBASE + 99)
  255. Global Const ERROR_CMD_TOO_LONG = (RASBASE + 100)
  256. Global Const ERROR_UNSUPPORTED_BPS = (RASBASE + 101)
  257. Global Const ERROR_UNEXPECTED_RESPONSE = (RASBASE + 102)
  258. Global Const ERROR_INTERACTIVE_MODE = (RASBASE + 103)
  259. Global Const ERROR_BAD_CALLBACK_NUMBER = (RASBASE + 104)
  260. Global Const ERROR_INVALID_AUTH_STATE = (RASBASE + 105)
  261. Global Const ERROR_WRITING_INITBPS = (RASBASE + 106)
  262. Global Const ERROR_INVALID_WIN_HANDLE = (RASBASE + 107)
  263. Global Const ERROR_NO_PASSWORD = (RASBASE + 108)
  264. Global Const ERROR_NO_USERNAME = (RASBASE + 109)
  265. Global Const ERROR_CANNOT_START_STATE_MACHINE = (RASBASE + 110)
  266. Global Const ERROR_GETTING_COMMSTATE = (RASBASE + 111)
  267. Global Const ERROR_SETTING_COMMSTATE = (RASBASE + 112)
  268. Global Const ERROR_COMM_FUNCTION = (RASBASE + 113)
  269. Global Const ERROR_CONFIGURATION_PROBLEM = (RASBASE + 114)
  270. Global Const ERROR_X25_DIAGNOSTIC = (RASBASE + 115)
  271. Global Const ERROR_TOO_MANY_LINE_ERRORS = (RASBASE + 116)
  272. Global Const ERROR_OVERRUN = (RASBASE + 117)
  273. Global Const ERROR_ACCT_EXPIRED = (RASBASE + 118)
  274. Global Const ERROR_CHANGING_PASSWORD = (RASBASE + 119)
  275. Global Const ERROR_NO_ACTIVE_ISDN_LINES = (RASBASE + 120)
  276. Global Const ERROR_NO_ISDN_CHANNELS_AVAILABLE = (RASBASE + 121)
  277. Global Const RASBASEEND = (RASBASE + 121)
  278.  
  279. Sub VBRASDial (rVBRAS_DIAL_INFO As VBRAS_DIAL_INFO_TYPE, hwndNotifier As Integer, lhConnection As Long, nResult As Integer)
  280. '**************************************************************************
  281. 'Purpose:   Initiates RAS connection
  282. 'Inputs:
  283.     'rVBRAS_DIAL_INFO    dial information
  284.     'hwndNotifier   handle to window to receive messages
  285. 'Assumes:
  286. 'Returns:
  287.     'lhConnection     handle to connection
  288.     'nResult         error code from RASAPI16, =0 if success
  289. 'Effects:
  290. '**************************************************************************
  291.     
  292.     Dim rRASDIALPARAMS As RASDIALPARAMS
  293.     Dim sPhonebookPath As String
  294.     Dim bPBIsNull As Integer                 'True if user hasn't specified phonebook
  295.     
  296.     lhConnection = 0  'ensure is null
  297.     
  298.     'using a non-default phonebook?
  299.     If rVBRAS_DIAL_INFO.PhoneBook = "" Then
  300.     bPBIsNull = True
  301.     Else
  302.     sPhonebookPath = rVBRAS_DIAL_INFO.PhoneBook + Chr$(0)
  303.     End If
  304.  
  305.     'set defaults "*" indicates entry in phonebook should be used
  306.     If rVBRAS_DIAL_INFO.CallbackNumber = "" And (rVBRAS_DIAL_INFO.entryname) <> "" Then
  307.         rVBRAS_DIAL_INFO.CallbackNumber = "*"
  308.     End If
  309.     If rVBRAS_DIAL_INFO.Domain = "" And (rVBRAS_DIAL_INFO.entryname) <> "" Then
  310.         rVBRAS_DIAL_INFO.Domain = "*"
  311.     End If
  312.     
  313.     'convert dial info to null-terminated strings
  314.     rRASDIALPARAMS.dwSize = Len(rRASDIALPARAMS)
  315.     rRASDIALPARAMS.szEntryName = rVBRAS_DIAL_INFO.entryname + Chr$(0)
  316.     rRASDIALPARAMS.szPhoneNumber = rVBRAS_DIAL_INFO.PhoneNumber + Chr$(0)
  317.     rRASDIALPARAMS.szCallbackNumber = rVBRAS_DIAL_INFO.CallbackNumber + Chr$(0)
  318.     rRASDIALPARAMS.szUserName = rVBRAS_DIAL_INFO.Username + Chr$(0)
  319.     rRASDIALPARAMS.szPassword = rVBRAS_DIAL_INFO.Password + Chr$(0)
  320.     rRASDIALPARAMS.szDomain = rVBRAS_DIAL_INFO.Domain + Chr$(0)
  321.     
  322.     'use a different call depending on phonebook
  323.     If bPBIsNull Then
  324.     
  325.     nResult = RASDIAL&(ByVal 0&, ByVal 0&, rRASDIALPARAMS, ByVal 0&, hwndNotifier, lhConnection)
  326.  
  327.     Else
  328.  
  329.     nResult = RASDIAL&(ByVal 0&, sPhonebookPath, rRASDIALPARAMS, ByVal 0&, hwndNotifier, lhConnection)
  330.  
  331.     End If
  332.  
  333. End Sub
  334.  
  335. Sub VBRASGetConnections (nConnections As Long, alhConnection() As Long, asConnectionName() As String, nResult As Integer)
  336. '**************************************************************************
  337. 'Purpose:   returns active RAS connections
  338. 'Inputs:
  339. 'Assumes:
  340. 'Returns:
  341.     'nConnections       Number of Connections (Max is mnVBRAS_MAX_CONNECTIONS)
  342.     'alhConnection()     Handles to connections (array numbers start at 1)
  343.     'asConnectionName()  Name or Phone number of connections
  344.     'nResult            RASAPI16 error code if non-zero
  345. 'Effects:
  346. '**************************************************************************
  347.  
  348.     Dim nLoopCount As Integer
  349.     Static aRASCONN(1 To mnVBRAS_MAX_CONNECTIONS) As RASCONN
  350.     Dim lBufferSize As Long
  351.  
  352.     'RASAPI16 requires first element must hold size of buffer array
  353.     lBufferSize = mnVBRAS_MAX_CONNECTIONS * Len(aRASCONN(1))
  354.     aRASCONN(1).dwSize = Len(aRASCONN(1))
  355.     
  356.     nResult = RasEnumConnections(aRASCONN(1), lBufferSize, nConnections)
  357.     
  358.     If nConnections > 0 Then
  359.     ReDim alhConnection(nConnections)
  360.     ReDim asConnectionName(nConnections)
  361.     For nLoopCount = 1 To nConnections
  362.         alhConnection(nLoopCount) = aRASCONN(nLoopCount).hrasconn
  363.         asConnectionName(nLoopCount) = aRASCONN(nLoopCount).szEntryName
  364.     Next
  365.     End If
  366.  
  367. End Sub
  368.  
  369. Sub VBRASGetConnState (ByVal lhConnection As Long, iConnectionState As Integer, iErrorCode As Integer, sDeviceName As String, sDeviceType As String, nResult As Integer)
  370. '**************************************************************************
  371. 'Purpose:   returns information about a lhConnection, given a valid handle
  372. 'Inputs:
  373.     'lhConnection     handle to lhConnection
  374. 'Assumes:   handle is valid, but RASAPI16 should return error if not
  375. 'Returns:
  376.     'iConnectionState   one of _RASCONNSTATE constants
  377.     'iErrorCode         RAS error code, if relevant
  378.     'sDeviceName        name of device
  379.     'sDeviceType        device type
  380.     'nResult            RASAPI16 error code if non-zero
  381. 'Effects:
  382. '**************************************************************************
  383.  
  384.     Dim rRASConnStatus As RASCONNSTATUS
  385.     
  386.     rRASConnStatus.dwSize = Len(rRASConnStatus)
  387.     
  388.     nResult = RasGetConnectStatus&(lhConnection, rRASConnStatus)
  389.     
  390.     iConnectionState = rRASConnStatus.rasconnstate
  391.     iErrorCode = rRASConnStatus.dwError
  392.     sDeviceName = rRASConnStatus.szDevicename
  393.     sDeviceType = rRASConnStatus.szDeviceType
  394.  
  395. End Sub
  396.  
  397. Function VBRASGetConnStateString (ConnState As Integer) As String
  398. '**************************************************************************
  399. 'Purpose:   returns strings describing RAS status codes
  400. 'Inputs:
  401.     'ConState       RAS status code
  402. 'Assumes:
  403. 'Returns:   descriptive string
  404. 'Effects:
  405. '**************************************************************************
  406.     
  407.     Select Case ConnState
  408.  
  409.     Case RAS_OpenPort
  410.         
  411.         VBRASGetConnStateString = "The communication port is about to be opened."
  412.     
  413.     Case RAS_PortOpened
  414.     
  415.         VBRASGetConnStateString = "The communication port has been opened successfully."
  416.     
  417.     Case RAS_ConnectDevice
  418.     
  419.         VBRASGetConnStateString = "A device is about to be connected."
  420.     
  421.     Case RAS_DeviceConnected
  422.     
  423.         VBRASGetConnStateString = "A device has connected successfully. "
  424.     
  425.     Case RAS_AllDevicesConnected
  426.     
  427.         VBRASGetConnStateString = "All devices in the device chain have successfully connected."
  428.     
  429.     Case RAS_Authenticate
  430.     
  431.         VBRASGetConnStateString = "The authentication process is starting."
  432.     
  433.     Case RAS_AuthNotify
  434.     
  435.         VBRASGetConnStateString = "An authentication event has occurred."
  436.     
  437.     Case RAS_AuthRetry
  438.     
  439.         VBRASGetConnStateString = "The client has requested another validation attempt with a new username/password/domain."
  440.     
  441.     Case RAS_AuthCallback
  442.     
  443.         VBRASGetConnStateString = "The Remote Access server has requested a callback number."
  444.     
  445.     Case RAS_AuthChangePassword
  446.     
  447.         VBRASGetConnStateString = "The client has requested to change the password on the account."
  448.     
  449.     Case RAS_AuthProject
  450.     
  451.         VBRASGetConnStateString = "The projection phase is starting."
  452.     
  453.     Case RAS_AuthLinkSpeed
  454.     
  455.         VBRASGetConnStateString = "The link speed calculation phase is starting."
  456.     
  457.     Case RAS_AuthAck
  458.     
  459.         VBRASGetConnStateString = "An authentication request is being acknowledged."
  460.     
  461.     Case RAS_ReAuthenticate
  462.     
  463.         VBRASGetConnStateString = "Reauthentication (after callback) is starting."
  464.     
  465.     Case RAS_Authenticated
  466.     
  467.         VBRASGetConnStateString = "The client has successfully completed authentication."
  468.     
  469.     Case RAS_PrepareForCallback
  470.     
  471.         VBRASGetConnStateString = "The line is about to disconnect in preparation for callback."
  472.     
  473.     Case RAS_WaitForModemReset
  474.     
  475.         VBRASGetConnStateString = "The client is delaying in order to give the modem time to reset itself in preparation for callback."
  476.     
  477.     Case RAS_WaitForCallback
  478.     
  479.         VBRASGetConnStateString = "The client is waiting for an incoming call from the Remote Access server."
  480.     
  481.     Case RAS_Interactive
  482.     
  483.         VBRASGetConnStateString = "This state corresponds to the Terminal state supported by RASPHONE.EXE."
  484.     
  485.     Case RAS_RetryAuthentication
  486.     
  487.         VBRASGetConnStateString = "This state corresponds to the Retry Authentication state supported by RASPHONE.EXE."
  488.     
  489.     Case RAS_CallbackSetByCaller
  490.     
  491.         VBRASGetConnStateString = "This state corresponds to the Callback state supported by RASPHONE.EXE."
  492.         
  493.     Case RAS_PasswordExpired
  494.     
  495.         VBRASGetConnStateString = "This state corresponds to the Change Password state supported by RASPHONE.EXE."
  496.     
  497.     Case RAS_Connected
  498.     
  499.         VBRASGetConnStateString = "Successful connection."
  500.     
  501.     Case RAS_Disconnected
  502.     
  503.         VBRASGetConnStateString = "Disconnection or failed connection."
  504.     
  505.     Case Else
  506.  
  507.         VBRASGetConnStateString = "Unknown State"
  508.  
  509.     End Select
  510.  
  511.  
  512. End Function
  513.  
  514. Function VBRASGetErrorString (ErrorCode As Integer) As String
  515. '**************************************************************************
  516. 'Purpose:   gets error string from RASAPI16
  517. 'Inputs:
  518.     'ErrorCode   numeric error code
  519. 'Assumes:
  520. 'Returns:   Corresponding error message
  521. 'Effects:
  522. '**************************************************************************
  523.  
  524.     Dim Buffer As String * 256
  525.     Dim nResult As Integer
  526.  
  527.     nResult = RasGetErrorString(ErrorCode, Buffer, Len(Buffer))
  528.     
  529.     If nResult = 0 Then
  530.     VBRASGetErrorString = Left$(Buffer, Len(Buffer) - 1)
  531.     Else
  532.     VBRASGetErrorString = "Unknown Error"
  533.     End If
  534.  
  535. End Function
  536.  
  537. Sub VBRASHangUp (lhConnection As Long, nResult As Integer)
  538. '**************************************************************************
  539. 'Purpose:   Hangs up lhConnection
  540. 'Inputs:
  541.     'lhConnection     handle to lhConnection to hang up
  542. 'Assumes:   Handle is valid
  543. 'Returns:
  544.     'nResult     RASAPI16 error code if non-zero
  545. 'Effects:
  546. '**************************************************************************
  547.     nResult = RASHangUp(lhConnection)
  548.  
  549. End Sub
  550.  
  551. Sub VBRASHangUpAll (nResult As Integer)
  552. '**************************************************************************
  553. 'Purpose:   Hangs up all connections
  554. 'Inputs:
  555. 'Assumes:   Handle is valid
  556. 'Returns:
  557.     'nResult     RASAPI16 error code if non-zero
  558. 'Effects:
  559. '**************************************************************************
  560.     
  561.     Dim ConnCount As Long
  562.     Dim ConnHandle() As Long
  563.     Dim ConnName() As String
  564.     
  565.     VBRASGetConnections ConnCount, ConnHandle(), ConnName(), nResult
  566.  
  567.     Do While ConnCount > 0 And nResult = 0
  568.  
  569.     VBRASHangUp ConnHandle(ConnCount), nResult
  570.     ConnCount = ConnCount - 1
  571.     
  572.     Loop
  573.     
  574. End Sub
  575.  
  576.