Ras.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. unit Ras;
  2. interface
  3. uses
  4. Windows, SysUtils,Classes,ExtCtrls,Forms, Dialogs;
  5. const
  6. rasapi32 = 'rasapi32.dll';
  7. UNLEN = 256; // Maximum user name length
  8. PWLEN = 256; // Maximum password length
  9. CNLEN = 15; // Computer name length
  10. DNLEN = CNLEN; // Maximum domain name length
  11. RAS_MaxDeviceType = 16;
  12. RAS_MaxPhoneNumber = 128;
  13. RAS_MaxIpAddress = 15;
  14. RAS_MaxIpxAddress = 21;
  15. RAS_MaxEntryName = 256;
  16. RAS_MaxDeviceName = 128;
  17. RAS_MaxCallbackNumber = RAS_MaxPhoneNumber;
  18. RAS_MaxAreaCode = 10;
  19. RAS_MaxPadType = 32;
  20. RAS_MaxX25Address = 200;
  21. RAS_MaxFacilities = 200;
  22. RAS_MaxUserData = 200;
  23. RASCS_OpenPort = 0;
  24. RASCS_PortOpened = 1;
  25. RASCS_ConnectDevice = 2;
  26. RASCS_DeviceConnected = 3;
  27. RASCS_AllDevicesConnected = 4;
  28. RASCS_Authenticate = 5;
  29. RASCS_AuthNotify = 6;
  30. RASCS_AuthRetry = 7;
  31. RASCS_AuthCallback = 8;
  32. RASCS_AuthChangePassword = 9;
  33. RASCS_AuthProject = 10;
  34. RASCS_AuthLinkSpeed = 11;
  35. RASCS_AuthAck = 12;
  36. RASCS_ReAuthenticate = 13;
  37. RASCS_Authenticated = 14;
  38. RASCS_PrepareForCallback = 15;
  39. RASCS_WaitForModemReset = 16;
  40. RASCS_WaitForCallback = 17;
  41. RASCS_Projected = 18;
  42. RASCS_StartAuthentication = 19;
  43. RASCS_CallbackComplete = 20;
  44. RASCS_LogonNetwork = 21;
  45. RASCS_SubEntryConnected = 22;
  46. RASCS_SubEntryDisconnected= 23;
  47. RASCS_PAUSED = $1000;
  48. RASCS_Interactive = RASCS_PAUSED;
  49. RASCS_RetryAuthentication = (RASCS_PAUSED + 1);
  50. RASCS_CallbackSetByCaller = (RASCS_PAUSED + 2);
  51. RASCS_PasswordExpired = (RASCS_PAUSED + 3);
  52. RASCS_DONE = $2000;
  53. RASCS_Connected = RASCS_DONE;
  54. RASCS_Disconnected = (RASCS_DONE + 1);
  55. // If using RasDial message notifications, get the notification message code
  56. // by passing this string to the RegisterWindowMessageA() API.
  57. // WM_RASDIALEVENT is used only if a unique message cannot be registered.
  58. RASDIALEVENT = 'RasDialEvent';
  59. WM_RASDIALEVENT = $CCCD;
  60. // TRASPROJECTION
  61. RASP_Amb = $10000;
  62. RASP_PppNbf = $0803F;
  63. RASP_PppIpx = $0802B;
  64. RASP_PppIp = $08021;
  65. RASP_Slip = $20000;
  66. type
  67. tRasErrorEvent = Procedure(Sender:tObject;ErrString : String) of Object;
  68. tRasStateEvent = Procedure(Sender:tObject;NewState : Integer) of Object;
  69. THRASCONN = THandle;
  70. PHRASCONN = ^THRASCONN;
  71. TRASCONNSTATE = DWORD;
  72. PDWORD = ^DWORD;
  73. PBOOL = ^BOOL;
  74. TRASDIALPARAMS = packed record
  75. dwSize : DWORD;
  76. szEntryName : array [0..RAS_MaxEntryName] of Char;
  77. szPhoneNumber : array [0..RAS_MaxPhoneNumber] of Char;
  78. szCallbackNumber : array [0..RAS_MaxCallbackNumber] of Char;
  79. szUserName : array [0..UNLEN] of Char;
  80. szPassword : array [0..PWLEN] of Char;
  81. szDomain : array [0..DNLEN] of Char;
  82. {$IFDEF WINVER401}
  83. dwSubEntry : DWORD;
  84. dwCallbackId : DWORD;
  85. {$ENDIF}
  86. szPadding : array [0..2] of Char;
  87. end;
  88. PRASDIALPARAMS = ^TRASDIALPARAMS;
  89. TRASDIALEXTENSIONS = packed record
  90. dwSize : DWORD;
  91. dwfOptions : DWORD;
  92. hwndParent : HWND;
  93. reserved : DWORD;
  94. end;
  95. PRASDIALEXTENSIONS = ^TRASDIALEXTENSIONS;
  96. TRASCONNSTATUS = packed record
  97. dwSize : DWORD;
  98. RasConnState : TRASCONNSTATE;
  99. dwError : DWORD;
  100. szDeviceType : array [0..RAS_MaxDeviceType] of char;
  101. szDeviceName : array [0..RAS_MaxDeviceName] of char;
  102. szPadding : array [0..1] of Char;
  103. end;
  104. PRASCONNSTATUS = ^TRASCONNSTATUS;
  105. TRASCONN = packed record
  106. dwSize : DWORD;
  107. hRasConn : THRASCONN;
  108. szEntryName : array [0..RAS_MaxEntryName] of char;
  109. szDeviceType : array [0..RAS_MaxDeviceType] of char;
  110. szDeviceName : array [0..RAS_MaxDeviceName] of char;
  111. szPadding : array [0..0] of Char;
  112. end;
  113. PRASCONN = ^TRASCONN;
  114. TRASENTRYNAME = packed record
  115. dwSize : DWORD;
  116. szEntryName : array [0..RAS_MaxEntryName] of char;
  117. szPadding : array [0..2] of Char;
  118. end;
  119. PRASENTRYNAME = ^TRASENTRYNAME;
  120. TArrayRasEntryName = Array[0..0] of TRasEntryName;
  121. PArrayRasEntryName = ^tArrayRasEntryName;
  122. TRASENTRYDLG = packed record
  123. dwSize : DWORD;
  124. hWndOwner : HWND;
  125. dwFlags : DWORD;
  126. xDlg : LongInt;
  127. yDlg : LongInt;
  128. szEntry : array [0..RAS_MaxEntryName] of char;
  129. dwError : DWORD;
  130. Reserved : DWORD;
  131. Reserved2 : DWORD;
  132. szPadding : array [0..2] of Char;
  133. end;
  134. PRASENTRYDLG = ^TRASENTRYDLG;
  135. TRASPROJECTION = integer;
  136. TRASPPPIP = record
  137. dwSize : DWORD;
  138. dwError : DWORD;
  139. szIpAddress : array [0..RAS_MaxIpAddress] of char;
  140. end;
  141. {************************************************************}
  142. {* *}
  143. {* tRasConnection - Object *}
  144. {* *}
  145. {************************************************************}
  146. TRasConnection = class;
  147. RasIdentifier = packed Record
  148. rasHandle : tHRasConn;
  149. RasObject : tRasConnection;
  150. end;
  151. tRasIdentifier = ^RasIdentifier;
  152. TRasConnection = class(tComponent)
  153. private
  154. fHandle : tHRasConn;
  155. fOwner : tComponent;
  156. fConnected : boolean;
  157. fAborted : boolean;
  158. fTimer : tTimer;
  159. fReady : Boolean;
  160. fState : Integer;
  161. fError : Integer;
  162. fErrMsg : String;
  163. fStateChange: tRasStateEvent;
  164. fErrorProc : tRasErrorEvent;
  165. fDialParams : tRasDialParams;
  166. Procedure TimeOut(Sender : tObject);
  167. Procedure SetState(Value:integer);
  168. Procedure SetConnected(Value : Boolean);
  169. Procedure DialUp;
  170. Procedure AbortDial;
  171. Public
  172. Constructor Create(AOwner:tComponent);override;
  173. Destructor Destroy; override;
  174. Function Connectwith(Ras : String) : Boolean;
  175. Procedure Hangup;
  176. Property Handle : tHRasConn read fHandle;
  177. property Connected : Boolean read fConnected write SetConnected;
  178. property State : integer read fState write SetState;
  179. Property Aborted : boolean read fAborted;
  180. Property Error : Integer read fError;
  181. Property ErrMsg : String read fErrMsg;
  182. published
  183. property onStateChange : tRasStateEvent read fStateChange write fStateChange;
  184. property onError : tRasErrorEvent read fErrorProc write fErrorProc;
  185. end;
  186. {************************************************************}
  187. {* *}
  188. {* Pascal Interfaces *}
  189. {* *}
  190. {************************************************************}
  191. Function RasEnumEntries(Reserved : Pointer; // reserved, must be NIL
  192. szPhonebook : PChar; // full path and filename of phonebook file
  193. lpRasEntryName : PArrayRASENTRYNAME; // buffer to receive entries
  194. var lpcb : integer; // size in bytes of buffer
  195. var lpcEntries : integer // number of entries written to buffer
  196. ) : Integer;
  197. function RasDial(RasDialExtensions: PRASDIALEXTENSIONS;
  198. PhoneBook : PChar;
  199. RasDialParams : tRASDIALPARAMS;
  200. NotifierType : DWORD;
  201. Notifier : Pointer;
  202. var RasConn : tHRASCONN
  203. ): DWORD;
  204. function RasHangup(RasConn: THRASCONN): DWORD;
  205. function RasGetEntryDialParams(
  206. szPhonebook : PChar; // pointer to the full path and filename of the phonebook file
  207. var rasdialparams : tRASDIALPARAMS; // pointer to a structure that receives the connection parameters
  208. var fPassword : BOOL // indicates whether the user's password was retrieved
  209. ) : DWORD;
  210. function RasGetErrorString(
  211. uErrorValue : DWORD // error to get string for
  212. ): String;
  213. function RasEditPhonebookEntry(
  214. hWndParent : HWND; // handle to the parent window of the dialog box
  215. Phonebook : String; // pointer to the full path and filename of the phonebook file
  216. EntryName : String // pointer to the phonebook entry name
  217. ) : DWORD;
  218. function RasCreatePhonebookEntry(
  219. hWndParent : HWND; // handle to the parent window of the dialog box
  220. Phonebook : String // pointer to the full path and filename of the phonebook file
  221. ) : DWORD;
  222. function RasEnumConnections(
  223. pRasConn : PRASCONN; // buffer to receive connections data
  224. var CB : LongInt; // size in bytes of buffer
  225. var Connections : DWORD // number of connections written to buffer
  226. ) : DWORD;
  227. Function RasCountConnections : Integer;
  228. {************************************************************}
  229. {* *}
  230. {* original Interfaces *}
  231. {* *}
  232. {************************************************************}
  233. function RasHangupA(RasConn: THRASCONN): DWORD; stdcall;
  234. function RasDialA(RasDialExtensions: PRASDIALEXTENSIONS;
  235. PhoneBook : PChar;
  236. RasDialParams : PRASDIALPARAMS;
  237. NotifierType : DWORD;
  238. Notifier : Pointer;
  239. RasConn : PHRASCONN
  240. ): DWORD; stdcall;
  241. function RasGetErrorStringA(
  242. uErrorValue : DWORD; // error to get string for
  243. szErrorString : PChar; // buffer to hold error string
  244. cBufSize : DWORD // size, in characters, of buffer
  245. ): DWORD; stdcall;
  246. function RasConnectionStateToString(nState : Integer) : String;
  247. function RasGetConnectStatusA(
  248. hRasConn: THRASCONN; // handle to RAS connection of interest
  249. lpRasConnStatus : PRASCONNSTATUS // buffer to receive status data
  250. ): DWORD; stdcall;
  251. function RasEnumConnectionsA(
  252. pRasConn : PRASCONN; // buffer to receive connections data
  253. pCB : PDWORD; // size in bytes of buffer
  254. pcConnections : PDWORD // number of connections written to buffer
  255. ) : DWORD; stdcall
  256. function RasEnumEntriesA(
  257. Reserved : Pointer; // reserved, must be NIL
  258. szPhonebook : PChar; // full path and filename of phonebook file
  259. lpRasEntryName : PRASENTRYNAME; // buffer to receive entries
  260. lpcb : PDWORD; // size in bytes of buffer
  261. lpcEntries : PDWORD // number of entries written to buffer
  262. ) : DWORD; stdcall;
  263. function RasGetEntryDialParamsA(
  264. lpszPhonebook : PChar; // pointer to the full path and filename of the phonebook file
  265. lprasdialparams : PRASDIALPARAMS; // pointer to a structure that receives the connection parameters
  266. lpfPassword : PBOOL // indicates whether the user's password was retrieved
  267. ) : DWORD; stdcall;
  268. function RasEditPhonebookEntryA(
  269. hWndParent : HWND; // handle to the parent window of the dialog box
  270. lpszPhonebook : PChar; // pointer to the full path and filename of the phonebook file
  271. lpszEntryName : PChar // pointer to the phonebook entry name
  272. ) : DWORD; stdcall;
  273. //function RasEntryDlgA(
  274. // lpszPhonebook : PChar; // pointer to the full path and filename of the phone-book file
  275. // lpszEntry : PChar; // pointer to the name of the phone-book entry to edit, copy, or create
  276. // lpInfo : PRASENTRYDLG // pointer to a structure that contains additional parameters
  277. // ) : DWORD; stdcall;
  278. function RasCreatePhonebookEntryA(
  279. hWndParent : HWND; // handle to the parent window of the dialog box
  280. lpszPhonebook : PChar // pointer to the full path and filename of the phonebook file
  281. ) : DWORD; stdcall;
  282. function RasGetProjectionInfoA(
  283. hRasConn : THRASCONN; // handle that specifies remote access connection of interest
  284. RasProjection : TRASPROJECTION; // specifies type of projection information to obtain
  285. lpProjection : Pointer; // points to buffer that receives projection information
  286. lpcb : PDWORD // points to variable that specifies buffer size
  287. ) : DWORD; stdcall;
  288. function RasGetIPAddress: string;
  289. Procedure Register;
  290. implementation
  291. Procedure Register;
  292. Begin
  293. Registercomponents('Tests',[TRasConnection]);
  294. end;
  295. var RasObjectList : tlist;
  296. {************************************************************}
  297. {* *}
  298. {* tRasConnection - Object *}
  299. {* *}
  300. {************************************************************}
  301. Function FindRasIndex(Handle:tHRasConn):Integer;
  302. var I : Integer;
  303. Begin
  304. for I := 0 to RasObjectList.Count -1 do
  305. begin
  306. if tRasIdentifier(RasObjectList[I]).rasHandle = Handle then
  307. begin
  308. Result := I;
  309. Exit;
  310. end;
  311. end;
  312. Result := -1;
  313. end;
  314. Constructor tRasConnection.Create(AOwner : tComponent);
  315. Begin
  316. inherited create(AOwner);
  317. fHandle := 0;
  318. fOwner := AOwner;
  319. fConnected := False;
  320. fTimer := tTimer.Create(nil);
  321. fReady := false;
  322. fState := -1;
  323. fAborted := false;
  324. With fTimer do
  325. begin
  326. enabled := false;
  327. Interval := 30000;
  328. onTimer := TimeOut;
  329. end;
  330. RasObjectlist.Add(@self);
  331. end;
  332. Destructor tRasConnection.Destroy;
  333. Begin
  334. if connected then RasHangup(Handle);
  335. fTimer.free;
  336. inherited destroy;
  337. end;
  338. Procedure tRasConnection.SetState(Value:Integer);
  339. Begin
  340. If fState <> Value then
  341. begin
  342. fState := Value;
  343. If Value = RASCS_DONE then
  344. begin
  345. fReady := true;
  346. fConnected := true;
  347. fTimer.Enabled := false;
  348. end;
  349. if Assigned(OnStateChange) then
  350. OnStateChange(self,Value);
  351. end;
  352. end;
  353. Procedure tRasConnection.SetConnected(Value:Boolean);
  354. Begin
  355. If fConnected <> Value then
  356. begin
  357. fAborted := False;
  358. if Value then
  359. DialUp
  360. else
  361. Hangup;
  362. end;
  363. end;
  364. Procedure MyDialFunc1(Hndl : tHRasConn;
  365. MsNum : uint;
  366. NewState : SmallInt;
  367. ActError : integer;
  368. xError : Integer); stdcall;
  369. {*********************************************************************************}
  370. {* This callback doesn't know which tRasconnection is to receive the information *}
  371. {*********************************************************************************}
  372. Var I : Integer;
  373. RasObj : tRasConnection;
  374. begin
  375. I := FindRasIndex(Hndl);
  376. if I < 0 then exit;
  377. RasObj := tRasIdentifier(RasObjectList[I]).rasObject;
  378. with RasObj do begin
  379. If ActError = 0 then
  380. begin
  381. State := NewState;
  382. end
  383. else
  384. begin
  385. fError := ActError;
  386. fErrMsg := RasGetErrorString(ActError);
  387. AbortDial;
  388. If Assigned(OnError) then
  389. OnError(RasObj,ErrMsg);
  390. end;
  391. end;
  392. end;
  393. Procedure tRasConnection.DialUp;
  394. { Dial with given DialParams }
  395. var thisRas : tRasIdentifier;
  396. R : Integer;
  397. Begin
  398. fError := 0;
  399. Connected := false; { Hangup any pending connection }
  400. fHandle := 0;
  401. R := RasDial(nil,nil,fDialParams,1,@MyDialFunc1,fHandle);
  402. If R <> 0 then begin
  403. Raise Exception.create('Verbindungsfehler : '+ErrMsg);
  404. end;
  405. fTimer.Enabled := True;
  406. If fHandle <= 0 then exit;
  407. new(thisRas);
  408. thisRas.rasHandle := fhandle;
  409. thisRas.RasObject := Self;
  410. RasObjectList.Add(thisRas);
  411. While not fReady do
  412. begin
  413. Application.Handlemessage;
  414. Application.ProcessMessages;
  415. end;
  416. fTimer.enabled := false;
  417. end;
  418. Function tRasConnection.Connectwith(Ras : String) : Boolean;
  419. var HavePassWord : bool;
  420. I : integer;
  421. R : Integer;
  422. begin
  423. Result := False;
  424. fReady := False;
  425. Fillchar(fDialParams,SizeOf(fDialParams),0);
  426. fDialParams.dwSize := SizeOf(fDialParams);
  427. for I := 1 to length(Ras) do
  428. fDialParams.szEntryName[Pred(I)] := Ras[I];
  429. HavePassWord := False;
  430. R := RasGetEntryDialParams(nil,fDialParams,HavePassWord);
  431. if R <> 0 then
  432. begin
  433. { couldn't get the Dial Params !!! }
  434. fAborted := true;
  435. exit;
  436. end;
  437. if not havePassword then
  438. begin
  439. { TODO : Passwort - Dialog einfügen }
  440. end;
  441. DialUp;
  442. Result := Connected;
  443. end;
  444. Procedure tRasConnection.Hangup;
  445. var RasIndex : Integer;
  446. thisRas : tRasIdentifier;
  447. begin
  448. fConnected := False;
  449. fTimer.Enabled := false;
  450. RasHangup(Handle);
  451. If Handle = 0 then Exit;
  452. RasIndex := FindRasIndex(Handle);
  453. if rasIndex >= 0 then
  454. begin
  455. ThisRas := RasObjectList.Items[RasIndex];
  456. DisPose(ThisRas);
  457. RasObjectlist.Delete(RasIndex);
  458. end;
  459. end;
  460. Procedure tRasConnection.AbortDial;
  461. begin
  462. Hangup;
  463. fAborted := True;
  464. fReady := True;
  465. end;
  466. Procedure tRasConnection.TimeOut(Sender : tObject);
  467. { The connection was timed out }
  468. begin
  469. AbortDial;
  470. end;
  471. {************************************************************}
  472. {* *}
  473. {* Pascal Interfaces *}
  474. {* *}
  475. {************************************************************}
  476. Function RasEnumEntries(Reserved : Pointer; // reserved, must be NIL
  477. szPhonebook : PChar; // full path and filename of phonebook file
  478. lpRasEntryName : PArrayRASENTRYNAME; // buffer to receive entries
  479. var lpcb : integer; // size in bytes of buffer
  480. var lpcEntries : integer // number of entries written to buffer
  481. ) : Integer;
  482. Begin
  483. Result := RasEnumEntriesA(Reserved,szPhonebook,@lpRasEntryName^[0],@lpcb,@lpcEntries);
  484. end;
  485. function RasDial(RasDialExtensions: PRASDIALEXTENSIONS;
  486. PhoneBook : PChar;
  487. RasDialParams : tRASDIALPARAMS;
  488. NotifierType : DWORD;
  489. Notifier : Pointer;
  490. var RasConn : tHRASCONN
  491. ): DWORD;
  492. Begin
  493. RasDial := RasDialA(RasDialExtensions,Phonebook,@RasDialParams,NotifierType,
  494. Notifier,@RasConn);
  495. end;
  496. function RasHangup(RasConn: THRASCONN): DWORD;
  497. Var RASConnStatus : TRasConnStatus;
  498. Status : Integer;
  499. Begin
  500. FillChar(RasConnStatus, SizeOf(RasConnStatus), 0);
  501. RasConnStatus.dwSize := SizeOf(RasConnStatus);
  502. {Status := }RasGetConnectStatusA(RasConn, @RasConnStatus);
  503. RasHangup := RasHangupA(RasConn);
  504. Repeat
  505. Status := RasGetConnectStatusA(RasConn, @RasConnStatus);
  506. sleep(0);
  507. Until Status = ERROR_INVALID_HANDLE;
  508. end;
  509. function RasGetEntryDialParams(
  510. szPhonebook : PChar; // pointer to the full path and filename of the phonebook file
  511. var rasdialparams : tRASDIALPARAMS; // pointer to a structure that receives the connection parameters
  512. var fPassword : BOOL // indicates whether the user's password was retrieved
  513. ) : DWORD;
  514. begin
  515. Result := RasGetEntryDialParamsA(szPhonebook,@RasDialParams,@fPassword);
  516. end;
  517. function RasGetErrorString(
  518. uErrorValue : DWORD // error to get string for
  519. ): String;
  520. Begin
  521. SetLength(Result,256);
  522. If RasGetErrorStringA(uErrorValue,PChar(Result),256) <> 0 then
  523. Result := '';
  524. SetLength(Result,Pos(#0,Result));
  525. end;
  526. function RasEditPhonebookEntry(
  527. hWndParent : HWND; // handle to the parent window of the dialog box
  528. Phonebook : String; // pointer to the full path and filename of the phonebook file
  529. EntryName : String // pointer to the phonebook entry name
  530. ) : DWORD;
  531. begin
  532. Result := RasEditPhonebookEntryA(hWndParent,Pchar(Phonebook),PChar(Entryname));
  533. end;
  534. function RasCreatePhonebookEntry(
  535. hWndParent : HWND; // handle to the parent window of the dialog box
  536. Phonebook : String // pointer to the full path and filename of the phonebook file
  537. ) : DWORD;
  538. begin
  539. Result := RasCreatePhonebookEntryA(HwndParent,PChar(Phonebook));
  540. end;
  541. function RasEnumConnections(
  542. pRasConn : PRASCONN; // buffer to receive connections data
  543. var CB : LongInt; // size in bytes of buffer
  544. var Connections : DWORD // number of connections written to buffer
  545. ) : DWORD;
  546. begin
  547. Result := RasEnumConnectionsA(pRasConn,@CB,@Connections);
  548. end;
  549. Function RasCountConnections : Integer;
  550. var Sz : LongInt;
  551. Nr : DWord;
  552. begin
  553. Sz := 0;
  554. RasEnumConnections(nil,Sz,Nr);
  555. Result := Sz div SizeOf(tRasConn);
  556. end;
  557. {************************************************************}
  558. {* *}
  559. {* original Interfaces *}
  560. {* *}
  561. {************************************************************}
  562. function RasConnectionStateToString(nState : Integer) : String;
  563. begin
  564. case nState of
  565. RASCS_OpenPort: Result := 'Opening Port';
  566. RASCS_PortOpened: Result := 'Port Opened';
  567. RASCS_ConnectDevice: Result := 'Connecting Device';
  568. RASCS_DeviceConnected: Result := 'Device Connected';
  569. RASCS_AllDevicesConnected: Result := 'All Devices Connected';
  570. RASCS_Authenticate: Result := 'Starting Authentication';
  571. RASCS_AuthNotify: Result := 'Authentication Notify';
  572. RASCS_AuthRetry: Result := 'Authentication Retry';
  573. RASCS_AuthCallback: Result := 'Callback Requested';
  574. RASCS_AuthChangePassword: Result := 'Change Password Requested';
  575. RASCS_AuthProject: Result := 'Projection Phase Started';
  576. RASCS_AuthLinkSpeed: Result := 'Link Speed Calculation';
  577. RASCS_AuthAck: Result := 'Authentication Acknowledged';
  578. RASCS_ReAuthenticate: Result := 'Reauthentication Started';
  579. RASCS_Authenticated: Result := 'Authenticated';
  580. RASCS_PrepareForCallback: Result := 'Preparation For Callback';
  581. RASCS_WaitForModemReset: Result := 'Waiting For Modem Reset';
  582. RASCS_WaitForCallback: Result := 'Waiting For Callback';
  583. RASCS_Projected: Result := 'Projected';
  584. RASCS_StartAuthentication: Result := 'Start Authentication';
  585. RASCS_CallbackComplete: Result := 'Callback Complete';
  586. RASCS_LogonNetwork: Result := 'Logon Network';
  587. RASCS_SubEntryConnected: Result := '';
  588. RASCS_SubEntryDisconnected: Result := '';
  589. RASCS_Interactive: Result := 'Interactive';
  590. RASCS_RetryAuthentication: Result := 'Retry Authentication';
  591. RASCS_CallbackSetByCaller: Result := 'Callback Set By Caller';
  592. RASCS_PasswordExpired: Result := 'Password Expired';
  593. RASCS_Connected: Result := 'Connected';
  594. RASCS_Disconnected: Result := 'Disconnected';
  595. else
  596. Result := 'Connection state #' + IntToStr(nState);
  597. end;
  598. end;
  599. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  600. function RasGetIPAddress: string;
  601. var
  602. RASConns : TRasConn;
  603. dwSize : DWORD;
  604. dwCount : DWORD;
  605. RASpppIP : TRASPPPIP;
  606. begin
  607. Result := '';
  608. RASConns.dwSize := SizeOf(TRASConn);
  609. RASpppIP.dwSize := SizeOf(RASpppIP);
  610. dwSize := SizeOf(RASConns);
  611. if RASEnumConnectionsA(@RASConns, @dwSize, @dwCount) = 0 then begin
  612. if dwCount > 0 then begin
  613. dwSize := SizeOf(RASpppIP);
  614. RASpppIP.dwSize := SizeOf(RASpppIP);
  615. if RASGetProjectionInfoA(RASConns.hRasConn,
  616. RASP_PppIp,
  617. @RasPPPIP,
  618. @dwSize) = 0 then
  619. Result := StrPas(RASpppIP.szIPAddress);
  620. end;
  621. end;
  622. end;
  623. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  624. function RasDialA; external rasapi32 name 'RasDialA';
  625. function RasGetErrorStringA; external rasapi32 name 'RasGetErrorStringA';
  626. function RasHangUpA; external rasapi32 name 'RasHangUpA';
  627. function RasGetConnectStatusA; external rasapi32 name 'RasGetConnectStatusA';
  628. function RasEnumConnectionsA; external rasapi32 name 'RasEnumConnectionsA';
  629. function RasEnumEntriesA; external rasapi32 name 'RasEnumEntriesA';
  630. function RasGetEntryDialParamsA; external rasapi32 name 'RasGetEntryDialParamsA';
  631. function RasEditPhonebookEntryA; external rasapi32 name 'RasEditPhonebookEntryA';
  632. //function RasEntryDlgA; external rasapi32 name 'RasEntryDlgA';
  633. function RasCreatePhonebookEntryA; external rasapi32 name 'RasCreatePhonebookEntryA';
  634. function RasGetProjectionInfoA; external rasapi32 name 'RasGetProjectionInfoA';
  635. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
  636. initialization
  637. RasObjectList := tList.create;
  638. Finalization
  639. RasObjectList.Free;
  640. end.