As you can see from the timestamp, this was created over two years ago. the customer I created it for wanted it to be developed in VFP5 and able to run in 95 through win 2000.
It was tested in those environment.
I have a test form that was used for development and is available for emailing. any comments as to if it still works in the newer environments I would appricate it. that way we can pass this on.
**************************************************
*-- Class: rasdial (rasdial.vcx)
*-- ParentClass: custom
*-- BaseClass: custom
*-- Time Stamp: 05/05/00 11:27:14 AM
*
#INCLUDE "rasdial.h"
**************** the inards of the rasdial.h file *****************
#define UNLEN 256 && Maximum user name length
#define PWLEN 256 && Maximum password length
#define DNLEN 15 && Maximum domain name length
#define RAS_MaxAreaCode 10
#define RAS_MaxPhoneNumber 128
#define MAX_PATH 261
#define RAS_MaxDeviceType 16
#define RAS_MaxDeviceName 128
#define RAS_MaxPadType 32
#define RAS_MaxX25Address 200
#define RAS_MaxFacilities 200
#define RAS_MaxUserData 200
#define RAS_MaxEntryName 256
#define RAS_MaxPhoneNumber 128
#define RAS_MaxCallbackNumber RAS_MaxPhoneNumber
#define ERROR_INVALID_PARAMETER 87
#define ERROR_INVALID_SIZE 632
#define ERROR_BUFFER_INVALID 610
#define ERROR_BUFFER_TOO_SMALL 603
#define ERROR_CANNOT_OPEN_PHONEBOOK 621
#define ERROR_CANNOT_FIND_PHONEBOOK_ENTRY 623
#define ERROR_NOT_ENOUGH_MEMORY 8
**************** END OF the inards of the rasdial.h file *****************
*
DEFINE CLASS rasdial AS custom
*-- count of dialup entries returnied from first call to RasEnumEntries
HIDDEN intentrycnt
intentrycnt = 0
*-- Phone number to call returned from call to RasGetEntryProperties
HIDDEN chrphonenum
chrphonenum = ""
*-- User ID returned from call to RasGetEntryDialParams
HIDDEN chruserid
chruserid = ""
*-- User password passed from calling program
HIDDEN chruserpw
chruserpw = ""
*-- Return result from RasDial
HIDDEN intdialout
intdialout = 0
*-- return result from RasGetConnectStatus
HIDDEN intstatusret
intstatusret = 0
*-- connection handle from call with RasDial
HIDDEN inthandle
inthandle = 0
*-- call to RasGetconnectStatus reports connection status
HIDDEN intconnectstat
intconnectstat = 0
*-- call to RasGetconnectStatus reports connection error
HIDDEN intconnecterror
intconnecterror = 0
*-- name of entry to dial
HIDDEN chrentry
chrentry = ""
Name = "rasdial"
*-- lovation of phone book if NT system
HIDDEN chrpb
*-- the remote connection device type
chrdevicetype = .F.
*-- the remote connection name
chrdevicename = .F.
*-- array to hold the dialup entry names. Start with 3 dimension to actual size after call to RasEnumEntries
HIDDEN aryentries[3]
*-- convert integer to high low string to pass in structure. DWORD size is 4 bytes, 8 bits to a byte
PROCEDURE m_long2str
*. Function m_long2str - convert 4-byte integer into low-high format Character string.
PARAMETERS longval
PRIVATE intloop, chrret
chrret = ""
FOR i = 24 TO 0 STEP -8
chrret = CHR(INT(longval/(2^i))) + chrret
longval = MOD(longval, (2^i))
NEXT
RETURN chrret
ENDPROC
*-- convert string returned from structure to integer. DWORD size is 4 bytes, 8 bits to a byte
PROCEDURE m_str2long
*. Function m_str2long - convert lo-high ascii character representation into 4-byte integer.
PARAMETERS longstr
PRIVATE intloop, retval
retval = 0
FOR intloop = 0 TO 24 STEP 8
retval = retval + (ASC(longstr) * (2^intloop))
longstr = RIGHT(longstr, LEN(longstr) - 1)
NEXT
RETURN retval
ENDPROC
*-- must be called to initialize class with dialup info from phone book.
PROCEDURE m_startup
parameter chrPhoneBook
with this
if empty(chrPhoneBook)
.chrPB = null
else
.chrPB = chrPhoneBook
endif
*. m_startup gets the phone book entry names and the count. Stores names to class array
private chrConnSstatus, intStruSize,intEntCnt, intret, intloop, intOffset
*. chrConnSstatus - structure to hold name entries
*. intStruSize _ sizeof structure
*. intEntCnt - count of phonebook entries
*. intret - return of RasEnumEntries
*. initialize structure for first call to determine the count of entries for resizing of structure
chrConnSstatus = this.m_long2str(264) + ; && sizeof structure
replicate(chr(0),257)
*. set var types
intret = 0
intStruSize = 0
intEntCnt = 0
*. the first call to RasEnumEntries will return value of 603 to indicate structure is to small
*. if more then one entry. we make this call only to get the entry count in intEntCnt
intret = RasEnumEntries(null,null,@chrConnSstatus,@intStruSize,@intEntCnt)
*. make a array of pointers to hold entries
*. intEntCnt is how many entries
chrConnSstatus = ' && reset structure
for intloop = 1 to intEntCnt
chrConnSstatus = chrConnSstatus + .m_long2str(264) + ; && sizeof structure
replicate(chr(0),257)
next
*. get the entry names
intret = RasEnumEntries(null,null,@chrConnSstatus,@intStruSize,@intEntCnt)
*. store the name count
.intentrycnt = intEntCnt
*. demension array to hold names
dimension .aryentries(intEntCnt)
*. fill array with names
intOffset = 5
for intloop = 1 to intEntCnt
.aryentries(intloop) = .m_trim(substr(chrConnSstatus,intOffset,256))
intOffset = intOffset + 264
next
endwith
return
ENDPROC
*-- to remove all chr(0) from return string in structures. foxpro only works with chr(32) spaces.
HIDDEN PROCEDURE m_trim
parameter chrstr
*. when passing structure members all of the space is not used leaving the remainder with the
*. initialized chr(0). FoxPros trim function only works with spaces chr(32).
private intlen, intloop, chrret, chrone
intlen = 0
intloop = 0
chrret = '
chrone = '
if parameters() < 1
return .f.
endif
intlen = len(chrstr)
for intloop = 1 to intlen
chrone = substr(chrstr,intloop,1)
chrret = chrret + iif(between(asc(chrone),33,126),chrone,')
next
return chrret
ENDPROC
*-- return string that emulates the RASENTRY structure used by RasGetEntryPropertires
PROCEDURE m_rasentry
private chrRasEntry
*. define var type
chrRasEntry = '
with this
** setup the RASENTRY structure
chrRasEntry = .m_long2str(1768) + ; && sizeof structure
.m_long2str(0) + ; && connection options
.m_long2str(0) + ; && TAPI country indentifier
.m_long2str(0) + ; && country code of the phone number
replicate(chr(0),RAS_MaxAreaCode) + chr(0)+; && area code
replicate(chr(0),RAS_MaxPhoneNumber) + chr(0)+; && phone number to dial
.m_long2str(0) + ; && alternate offset
.m_long2str(0) + ; && ip address
.m_long2str(0) + ; && IP address of DNS server
.m_long2str(0) + ; && IP address of backup DNS server
.m_long2str(0) + ; && IP address of WIN server
.m_long2str(0) + ; && IP address of backup WIN server
.m_long2str(0) + ; && network protocol frame size
.m_long2str(0) + ; && network protocol to negotiate
.m_long2str(0) + ; && framing protacol to used by server
replicate(chr(0),MAX_PATH) + chr(0)+; &&
replicate(chr(0),MAX_PATH) + chr(0)+; &&
replicate(chr(0),MAX_PATH) + chr(0)+; &&
replicate(chr(0),RAS_MaxDeviceType) + chr(0)+; && RAS device referenced by szDeviceName
replicate(chr(0),RAS_MaxDeviceName) + chr(0)+; && name of TAPI device
replicate(chr(0),RAS_MaxPadType) + chr(0)+; && X.25 PAD type
replicate(chr(0),RAS_MaxX25Address) + chr(0)+; && X.25 address to connect to
replicate(chr(0),RAS_MaxFacilities) + chr(0)+; && facilities to request from the X.25 host
replicate(chr(0),RAS_MaxUserData) + chr(0)+; && addictional connection info to the X.25 host
.m_long2str(0) + ; && number of channels suported by device
.m_long2str(0) + ; && reserved set to 0
.m_long2str(0) && reserved set to 0
endwith
return chrRasEntry
ENDPROC
*-- return the number of phonebook entries. Entries for dialup networking are stored in registry
PROCEDURE m_entrycnt
*. return the entry count
return this.intentrycnt
ENDPROC
*-- fill passed array with entry names
PROCEDURE m_entrynames
parameter aryNames
if parameters() < 1
return .f.
endif
private intloop
*. define var type
intloop = 0
with this
*. demension the array
dimension aryNames(.intentrycnt)
*. transfer stored names to users array
for intloop = 1 to .intentrycnt
aryNames(intloop) = .aryentries(intloop)
next
endwith
return
ENDPROC
*-- make the connection to remote system Parametes: named entry, user ID, user password
PROCEDURE m_dial
parameters chrEntry, chrID, chrPW
private DialParams, intHandle, intRet, chrRASENTRY, chrPhonebook, intEntryInfoSize, chrphn
with this
*. DialParams - structure to pass
*. intHandle - handle to dialup connection
*. intRet - function return value
*. chrRASENTRY - structure to pass
*. define data types
*. chrPhonebook - phone book path and name here if NT system
*. intEntryInfoSize - sizeof chrRASENTRY structure
*. chrphn - dialout entry phone number
*. define data types
DialParams = '
intHandle = 0
intRet = 0
chrRASENTRY = '
intEntryInfoSize = 0
chrPhonebook = .chrPB
chrphn = '
*. ERROR CHECK FOR REQUIRED PARAMETERS
IF PARAMETERS() < 2
RETURN intHandle
ENDIF
IF TYPE("chrEntry") != 'C'
RETURN intHandle
else
.chrentry = alltrim(chrEntry)
ENDIF
IF TYPE("chrID") != 'C'
RETURN intHandle
else
.chruserid = alltrim(chrID)
ENDIF
IF TYPE("chrPW") != 'C' && IF not passed this will be logical, insure data type
chrPW = '
ENDIF
.chruserpw = alltrim(chrPW)
*. get the structure RASENTRY
chrRASENTRY = .m_rasentry()
intEntryInfoSize = len(chrRASENTRY)
intRet = RasGetEntryProperties(@chrPhonebook,@chrEntry,@chrRASENTRY,@intEntryInfoSize,0,0)
*. error checking
do case
case intRet = ERROR_INVALID_PARAMETER
.intConnectError = intRet
RETURN intHandle
case intRet = ERROR_INVALID_SIZE
.intConnectError = intRet
RETURN intHandle
case intRet = ERROR_BUFFER_INVALID
.intConnectError = intRet
RETURN intHandle
case intRet = ERROR_BUFFER_TOO_SMALL
.intConnectError = intRet
RETURN intHandle
case intRet = ERROR_CANNOT_OPEN_PHONEBOOK
.intConnectError = intRet
RETURN intHandle
case intRet = ERROR_CANNOT_FIND_PHONEBOOK_ENTRY
.intConnectError = intRet
RETURN intHandle
endcase
chrphn = .m_trim(substr(chrRASENTRY,24,RAS_MaxPhoneNumber))
.chrphonenum = chrphn && store for possible future use
*. DEFINE THE STRUCTURE lpRasDialParams
* m_long2str is passed a dwLength of 1052; since structure is 1052 bytes long.
DialParams = .m_long2str(1052) + ; && sizeof structure
replicate(chr(0),RAS_MaxEntryName) +chr(0)+; && not used
chrphn+ replicate(chr(0),RAS_MaxPhoneNumber-len(chrphn))+chr(0)+; && number to dial
replicate(chr(0),RAS_MaxCallbackNumber) +chr(0)+; && not used
chrID + replicate(chr(0),UNLEN-len(chrID)) +chr(0)+; && login id
chrPW + replicate(chr(0),PWLEN-len(chrPW)) +chr(0)+; && password
replicate(chr(0),DNLEN) +chr(0) && notused
intRet = RasDial(null,null,@DialParams,0,0,@intHandle)
.intConnectError = intRet && this will be zero if successful
.inthandle = intHandle
endwith
return intHandle
ENDPROC
*-- no parameters, return the connection status
PROCEDURE m_status
PRIVATE chrConnSstatus, intRet, intError, intStatus
*. define data types
chrConnSstatus = '
intRet = 0
intError = 0
intStatus = 0
with this
if .intConnectError != 0 && connectin failed on dialout try
return 0 && check with m_error on why it failed
endif
*. chrConnSstatus - THE STRUCTURE to be filled for connection status
*. m_long2str is passed a dwLength of 160; since structure is 160 bytes long.
*. prepare the structure
chrConnSstatus = .m_long2str(160) + ; && sizeof structure
.m_long2str(0) + ; && connection status
.m_long2str(0) + ; && if fail reason for failure
replicate(chr(0),RAS_MaxDeviceType) + chr(0)+; && type of connect device
replicate(chr(0),RAS_MaxDeviceName) + chr(0) && connect device name
intRet = RasGetConnectStatus(.inthandle,@chrConnSstatus)
if intRet != 0
.intStatusRet = intRet
return 0
endif
.intConnectStat = this.m_str2long(substr(chrConnSstatus,5,4)) && connection status
intStatus = .intConnectStat
intError = .m_str2long(substr(chrConnSstatus,9,4)) && connection error
.intConnectError = intError
.chrdevicetype = .m_trim(substr(chrConnSstatus,13,16)) && device type
.chrdevicename = .m_trim(substr(chrConnSstatus,30,128)) && device name
endwith
return intStatus
ENDPROC
*-- return the error on connection failure
PROCEDURE m_error
*. return the connection failure reason
return this.intConnectError
ENDPROC
*-- disconnect from remote system
PROCEDURE m_hangup
*. break the connection
=RasHangUp(this.inthandle)
ENDPROC
PROCEDURE Init
*. declare Ras functions for class
*. hangup the phone, release modem
DECLARE RasHangUp IN RASAPI32 integer hrasconn && connection handle
* Declare API function to get connection status
Declare Integer RasGetConnectStatus in RasAPI32; && return of zero on success
integer HRASCONN, ; && connection handle
string @RasGetConnectStatus && structure to recieve connection info
* Declare API function to dial remote system.
Declare Integer RasDial in RasAPI32 ; && return of zero on success
String lpRasDialExtensions, ; && not used, set to null
String lpszPhonebook, ; && if NT path to phone book, Win95 uses default book
String lpRasDialParams, ; && structure holding phonebook data
Integer dwNotifierType, ; && not used, set to zero
Integer lpvNotifier, ; && set to zero to operate in synchronously mode
Integer @lphRasConn && connection handle, set to zero
*. list entry names in phone book
DECLARE INTEGER RasEnumEntries IN rasapi32 ; && return of zero on success
STRING reserved,; && reserved set to null
STRING phonebook,; && dialup networking stores in registry, set to null
STRING @rasentry,; && structure to store entry names
INTEGER @lnSize,; && zise of structure
INTEGER @lnEntries && count of entries in phonebook
*. used to get phone number to dial passing it the entry name
DECLARE INTEGER RasGetEntryProperties IN rasapi32 ; && return of zero on success
string @lpszPhonebook,; && dialup networking stores in registry, set to null
string @lpszEntry,; && entry name to retrive phone number for
string @lpRasEntry,; && structure to hold return info on entry name
integer @lpdwEntryInfoSize,; && structure size
integer lpbDeviceInfo,; && device specific info, not used set to null
integer lpdwDeviceInfoSize && size of above, since null set to zero
*. used to retrive info on phone book entry, user id
DECLARE INTEGER RasGetEntryDialParams IN rasapi32 ; && return of zero on success
string lpszPhoneBook,; && dialup networking stores in registry, set to null
string @lpRasDialParams,; && structure to hold return info
integer @lpfPassword && flag to indicate if the return info holds password
ENDPROC
ENDDEFINE
*
*-- EndDefine: rasdial
**************************************************