TRas

Fuente: source/classes/tras.prg

TRas is FiveWin's Remote Access Service (RAS) class for managing dial-up connections on Windows. It wraps the Windows RAS API to initiate phone connections, monitor connection status, and hang up. TRas supports both manual and automatic (blocking) connection modes with timeout-based fail-safes.

Architecture

flowchart LR subgraph "FiveWin Application" A[TRas] B[oWnd
Window Handle] end subgraph "Windows RAS API" C[RaDial] D[RaGetConSt] E[RaHangUp] F[RaGetError] end subgraph "Phone Line / Modem" G[Dial-up Connection] end A -->|"initiates call"| C A -->|"polls status"| D A -->|"terminates"| E A -->|"error details"| F C --> G D --> A

Key DATA Members

DATATypeDefaultDescription
hRasNumeric0RAS connection handle returned by RaDial
cPhoneCharacter""Phone number to dial
cUserCharacter""Username for authentication
cPassCharacter""Password for authentication
cStatusCharacter""Human-readable connection status string
nStatusNumeric0Numeric RAS connection status code
nTimeoutNumeric60Timeout in seconds for auto-wait mode
lOperationLogical.F.Whether the last operation succeeded
cErrorCharacter""Last error message
cDevTypeCharacter""Device type (e.g. "modem")
cDevNameCharacter""Device name
bStatusBlockCallback codeblock invoked on each status change
aMsgStatusArrayInternal mapping of RAS status codes to descriptive strings

Methods

MethodDescription
New( oWnd, cPhone, cUser, cPass )Create a RAS instance. Requires a valid window handle, phone number, username, and password. Validates all parameters on construction.
Call( lMode, bStatus )Initiate the dial-up connection. If lMode is .T. (auto-wait), blocks until connected or timeout. Optionally sets bStatus callback.
Status()Poll the current connection status and update all status DATA members. Invokes bStatus callback if set.
HangUp()Terminate the RAS connection. Calls RaHangUp() with the stored handle.

Example: Dial-up with Auto-Wait

#include "FiveWin.ch"

function Main()

   local oWnd, oRas

   DEFINE WINDOW oWnd TITLE "RAS Dial-up"

   oRas := TRas():New( oWnd, "555-1234", "myuser", "mypass" )

   if oRas:lOperation
      // Auto-wait mode: blocks until connected (or timeout)
      if oRas:Call( .T. )
         MsgInfo( "Connected! Status: " + oRas:cStatus )
         // ... use the connection ...
         oRas:HangUp()
      else
         MsgStop( "Connection failed: " + oRas:cError )
      endif
   else
      MsgStop( "RAS initialization failed" )
   endif

return nil

Connection Status Values

CodeDescription
0Opening communication port
1Port opened
2Connecting to device
3Device connected, placing call
4All devices connected
5Verifying username and password
6Username and password accepted
7Retrying authentication
8Authentication callback in progress
14Authenticated
8192Connected successfully
8193Disconnected

Notes

Ver También