Написал вот примерчик, только осторожней там защиты от дурака и проверки на ошибки нету
| Код | program RasDemo; {$APPTYPE CONSOLE} uses windows; const RASEDFLAG_NoRename=$00000008; RAS_MaxAreaCode=10; RAS_MaxDeviceType =16; RAS_MaxPadType=32; RAS_MaxPhoneNumber=128; RAS_MaxDeviceName=128; RAS_MaxX25Address=200; RAS_MaxFacilities=200; RAS_MaxUserData=200; RAS_MaxEntryName=256; type TRasIpAddr=record a,b,c,d:byte end;
RASDEVINFO=record dwSize: DWORD; szDeviceType: array [0..RAS_MaxDeviceType] of AnsiChar; szDeviceName: array [0..RAS_MaxDeviceName] of AnsiChar; end; pRasDevInfo=^RASDEVINFO;
RASENTRY=record dwSize: DWORD; dwfOptions: DWORD; dwCountryID: DWORD; dwCountryCode: DWORD; szAreaCode: array [0..RAS_MaxAreaCode] of AnsiChar; szLocalPhoneNumber: array [0..RAS_MaxPhoneNumber] of AnsiChar; dwAlternateOffset: DWORD; ipaddr: TRasIpAddr; ipaddrDns: TRasIpAddr; ipaddrDnsAlt: TRasIpAddr; ipaddrWins: TRasIpAddr; ipaddrWinsAlt: TRasIpAddr; dwFrameSize: DWORD; dwfNetProtocols: DWORD; dwFramingProtocol: DWORD; szScript: array [0..Pred(MAX_PATH)] of AnsiChar; szAutodialDll: array [0..Pred(MAX_PATH)] of AnsiChar; szAutodialFunc: array [0..Pred(MAX_PATH)] of AnsiChar; szDeviceType: array [0..RAS_MaxDeviceType] of AnsiChar; szDeviceName: array [0..RAS_MaxDeviceName] of AnsiChar; szX25PadType: array [0..RAS_MaxPadType] of AnsiChar; szX25Address: array [0..RAS_MaxX25Address] of AnsiChar; szX25Facilities: array [0..RAS_MaxFacilities] of AnsiChar; szX25UserData: array [0..RAS_MaxUserData] of AnsiChar; dwChannels: DWORD; dwReserved1: DWORD; dwReserved2: DWORD; end; pRasEntry=^RASENTRY;
TRASENTRYDLG=packed record dwSize: DWORD; hwndOwner: HWND; dwFlags: DWORD; xDlg: LongInt; yDlg: LongInt; szEntry: array [0..RAS_MaxEntryName] of AnsiChar; dwError: DWORD; reserved: DWORD; reserved2: DWORD; szPadding: array [0..2] of AnsiChar; end; PRasEntryDlg=^TRASENTRYDLG;
function RasEnumDevices(lpRasDevInfo:PRasDevInfo;var lpcb,lpcDevices:DWORD):DWORD;stdcall; external 'RasApi32.dll' name 'RasEnumDevicesA';
function RasSetEntryProperties(lpszPhonebook:PChar;lpszEntry:PChar;lpRasEntry:PRasEntry; pdwEntryInfoSize:DWORD;lpbDeviceInfo:pByte;pdwDeviceInfoSize:DWORD):DWORD;stdcall; external 'RasApi32.dll' name 'RasSetEntryPropertiesA';
function RasEntryDlg(lpszPhonebook:PChar;lpszEntry:PChar;lpInfo:PRasEntryDlg):BOOL;stdcall; external 'RasDlg.dll' name 'RasEntryDlgA';
var re:RASENTRY;BufSize,count,i:DWORD;ed:TRASENTRYDLG; devices:array of RASDEVINFO;name:string; begin SetLength(devices,1); devices[0].dwSize:=SizeOf(RASDEVINFO); BufSize:=SizeOf(RASDEVINFO);count:=0; RasEnumDevices(nil,BufSize,count); if count=0 then begin writeln('No RAS-capable devices found'); readln end else begin SetLength(devices,count); RasEnumDevices(@devices[0],BufSize,count); for i:=0 to high(devices) do writeln(i+1,'. ',devices[i].szDeviceType,' ',devices[i].szDeviceName); write('Select device (by number:) >');readln(i); re.dwSize:=SizeOf(re); CopyMemory(@re.szDeviceType,@devices[i-1].szDeviceType,SizeOf(devices[i-1].szDeviceType)); CopyMemory(@re.szDeviceName,@devices[i-1].szDeviceName,SizeOf(devices[i-1].szDeviceName)); write('Enter phone number >');readln(re.szLocalPhoneNumber); write('Enter connection (for programmer - "phonebook entry") name >');readln(name); RasSetEntryProperties(nil,PChar(name),@re,SizeOf(re),nil,0); ed.dwSize:=SizeOf(ed); ed.dwFlags:=RASEDFLAG_NoRename; ed.reserved:=0; ed.reserved2:=0; RasEntryDlg(nil,PChar(name),@ed); end; end.
|
|