TRas
Source: 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
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
| DATA | Type | Default | Description |
|---|---|---|---|
hRas | Numeric | 0 | RAS connection handle returned by RaDial |
cPhone | Character | "" | Phone number to dial |
cUser | Character | "" | Username for authentication |
cPass | Character | "" | Password for authentication |
cStatus | Character | "" | Human-readable connection status string |
nStatus | Numeric | 0 | Numeric RAS connection status code |
nTimeout | Numeric | 60 | Timeout in seconds for auto-wait mode |
lOperation | Logical | .F. | Whether the last operation succeeded |
cError | Character | "" | Last error message |
cDevType | Character | "" | Device type (e.g. "modem") |
cDevName | Character | "" | Device name |
bStatus | Block | Callback codeblock invoked on each status change | |
aMsgStatus | Array | Internal mapping of RAS status codes to descriptive strings |
Methods
| Method | Description |
|---|---|
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
| Code | Description |
|---|---|
0 | Opening communication port |
1 | Port opened |
2 | Connecting to device |
3 | Device connected, placing call |
4 | All devices connected |
5 | Verifying username and password |
6 | Username and password accepted |
7 | Retrying authentication |
8 | Authentication callback in progress |
14 | Authenticated |
8192 | Connected successfully |
8193 | Disconnected |
Notes
- TRas requires a valid FiveWin window or dialog handle (
oWnd:hWnd) for the RAS API to post connection status notifications. - In auto-wait mode (
Call( .T. )), the method polls the connection status in a loop until connected, the timeout expires, orlPanicis set to.T.. - The
bStatuscallback codeblock is invoked on every status change, allowing UI updates during the connection process. - Always check
lOperationafter construction andCall()to verify success.