如何用delphi编写在win2000下的拨号程序。请给出代码。(100分)

  • 主题发起人 主题发起人 lukisy
  • 开始时间 开始时间
L

lukisy

Unregistered / Unconfirmed
GUEST, unregistred user!
如何用delphi编写在win2000下的拨号程序。请给出代码。谢谢!
 
这个问题以前已经有很多答案了,http://richsearch.com 全文检索一下包你找到一大堆
 
真的没有答案啊。
大家帮忙啊。
谁能告诉我该如何实现啊。
 
用api函数实现
 
什么api啊。
具体能说说吗?
98下到是能实现,但2000和以上的系统该怎么实现呢?
期待
 
我翻到了旧帖子:
首先要建立两个Unit文件
1、unit Ras;
interface
uses
Windows;
const
{$IFDEF WINVER400}
RAS_MaxEntryName = 256;
{$ELSE}
RAS_MaxEntryName = 20;
{$ENDIF}
rasapi32 = 'rasapi32.dll';
type
TRASENTRYNAME = packed record
dwSize : DWORD;
szEntryName : array [0..RAS_MaxEntryName] of char;
szPadding : array [0..2] of Char;
end;
PRASENTRYNAME = ^TRASENTRYNAME;
implementation
end.
2、
unit libRasDial;
interface
uses
Windows, SysUtils, Registry, WinSock, WinInet, Ras;
function _IsConnectedToInternet: Boolean;
function _DoConnect(hwndParent:HWND): Boolean;
function _GetRasConnNum: Integer;
procedure _DoNew(hwndParent:HWND);
function RasEnumEntriesA(Reserved: Pointer;
szPhonebook: PChar;
lpRasEntryName: PRASENTRYNAME;
lpcb : PDWORD;
lpcEntries : PDWORD
): DWORD; stdcall;
function RasGetErrorStringA(uErrorValue : DWORD;
szErrorString : PChar;
cBufSize : DWORD
): DWORD; stdcall;
function RasCreatePhonebookEntryA(hWndParent : HWND;
lpszPhonebook : PChar
) : DWORD; stdcall;
var Conn: DWORD;
implementation
const
INTERNET_CONNECTION_MODEM = 1;
INTERNET_CONNECTION_LAN = 2;
INTERNET_CONNECTION_PROXY = 4;
INTERNET_CONNECTION_MODEM_BUSY = 8;
function InternetGetConnectedState(lpdwFlags: LPDWORD;
dwReserved: DWORD): BOOL; stdcall; external 'WININET.DLL';
function _IsConnectedToInternet: Boolean;
var
dwConnectionTypes: Integer;
begin
try
dwConnectionTypes := INTERNET_CONNECTION_MODEM +
INTERNET_CONNECTION_LAN +
INTERNET_CONNECTION_PROXY;
if InternetGetConnectedState(@dwConnectionTypes, 0) then
Result := true
else
Result := false;
except
Result := false;
end;
end;
function _DoConnect(hwndParent:HWND):Boolean;
begin
Result:= false;
if _GetRasConnNum=0 then _DoNew(hwndParent);
if _GetRasConnNum=0 then exit;
InternetDial(hwndparent,
'',
INTERNET_AUTODIAL_FORCE_ONLINE,
@Conn,
0);
if Conn<>0 then Result:=true;
end;
function _GetRasConnNum: Integer;
var
Entries : array [0..15] of TRASENTRYNAME;
cb : DWORD;
cEntries : DWORD;
dwRet : DWORD;
Buf : array [0..127] of char;
begin
FillChar(Entries, SizeOf(Entries), 0);
Entries[0].dwSize := SizeOf(TRASENTRYNAME);
cb := SizeOf(Entries);
cEntries := 0;
dwRet := RasEnumEntriesA(NIL, NIL, @Entries[0], @cb, @cEntries);
if dwRet <> 0 then RasGetErrorStringA(dwRet, @Buf[0], SizeOf(Buf));
Result:= cEntries;
end;
procedure _DoNew(hwndParent:HWND);
var
dwRet: DWORD;
Buf : Array [0..127] of char;
begin
dwRet := RasCreatePhonebookEntryA(hwndParent, nil);
if dwRet <> 0 then RasGetErrorStringA(dwRet, @Buf[0], SizeOf(Buf));
end;
function RasEnumEntriesA; external rasapi32 name 'RasEnumEntriesA';
function RasGetErrorStringA; external rasapi32 name 'RasGetErrorStringA';
function RasCreatePhonebookEntryA; external rasapi32 name 'RasCreatePhonebookEntryA';
end.
然后你就可以调用这些函数了
procedure TMainForm.Buttn1Click(Sender: TObject);
begin
_DoConnect(0);//拨号
end;
procedure TMainForm.Buttn1Click(Sender: TObject);
begin
if Conn <> 0 then
InternetHangUp(Conn,0);//断开
end;
 
好多源码啊,不过下次能不能 先讲讲思想,给源码的再说
 
这方面的代码太多了
{$F+}
Unit RAS_API32;

Interface

Uses WinTypes, WinProcs, Dialogs;
{ Copyright (c) 1992, Microsoft Corporation, all rights reserved
Note: The 'dwSize' member of a structure X must be set to sizeof(X)
before calling the associated API, otherwise ERROR_INVALID_SIZE is
returned. The APIs determine the size using 2-byte packing (the
default for Microsoft compilers when no /Zp<n> option is supplied).
Users requiring non-default packing can use the 'dwSize' values
listed next to each 'dwSize' member in place of sizeof(X). }

Const
UNLEN = 256;
PWLEN = 256;
DNLEN = 15;
RAS_MaxEntryName = 256;
RAS_MaxDeviceName = 128;
RAS_MaxDeviceType = 16;
//RAS_MaxParamKey = 32;
//RAS_MaxParamValue = 128;
RAS_MaxPhoneNumber = 128;
RAS_MaxCallbackNumber = RAS_MaxPhoneNumber;
RAS_MaxIpAddress =15 ;//IP地址最大长度 add by LDS
RASP_PPPIP =$8021;//拨号连接的协议类型,该数值表示PPP连接
Type
//UINT = Word;
PHRASConn = ^HRASConn;
HRASConn = DWORD;


{ Pass this string to the RegisterWindowMessage() API to get the message
** number that will be used for notifications on the hwnd you pass to the
** RasDial() API. WM_RASDIALEVENT is used only if a unique message cannot be
** registered. }
const
RASDialEvent = 'RASDialEvent';
WM_RASDialEvent = $0CCCD;
{ Enumerates intermediate states to a Connection. (See RasDial) }
RASCS_Paused = $1000;
RASCS_Done = $2000;

RASBase = 600;
Success = 0;
{ Error Codes }
PENDING = (RASBase+0);
ERROR_INVALID_PORT_HANDLE = (RASBase+1);
ERROR_PORT_ALREADY_OPEN = (RASBase+2);
ERROR_BUFFER_TOO_SMALL = (RASBase+3);
ERROR_WRONG_INFO_SPECIFIED = (RASBase+4);
ERROR_CANNOT_SET_PORT_INFO = (RASBase+5);
ERROR_PORT_NOT_ConnECTED = (RASBase+6);
ERROR_EVENT_INVALID = (RASBase+7);
ERROR_DEVICE_DOES_NOT_EXIST = (RASBase+8);
ERROR_DEVICETYPE_DOES_NOT_EXIST = (RASBase+9);
ERROR_INVALID_BUFFER = (RASBase+10);
ERROR_ROUTE_NOT_AVAILABLE = (RASBase+11);
ERROR_ROUTE_NOT_ALLOCATED = (RASBase+12);
ERROR_INVALID_COMPRESSION_SPECIFIED = (RASBase+13);
ERROR_OUT_OF_BUFFERS = (RASBase+14);
ERROR_PORT_NOT_FOUND = (RASBase+15);
ERROR_ASYNC_REQUEST_PENDING = (RASBase+16);
ERROR_ALREADY_DISConnECTING = (RASBase+17);
ERROR_PORT_NOT_OPEN = (RASBase+18);
ERROR_PORT_DISConnECTED = (RASBase+19);
ERROR_NO_ENDPOINTS = (RASBase+20);
ERROR_CANNOT_OPEN_PHONEBOOK = (RASBase+21);
ERROR_CANNOT_LOAD_PHONEBOOK = (RASBase+22);
ERROR_CANNOT_FIND_PHONEBOOK_ENTRY = (RASBase+23);
ERROR_CANNOT_WRITE_PHONEBOOK = (RASBase+24);
ERROR_CORRUPT_PHONEBOOK = (RASBase+25);
ERROR_CANNOT_LOAD_STRING = (RASBase+26);
ERROR_KEY_NOT_FOUND = (RASBase+27);
ERROR_DISConnECTION = (RASBase+28);
ERROR_REMOTE_DISConnECTION = (RASBase+29);
ERROR_HARDWARE_FAILURE = (RASBase+30);
ERROR_USER_DISConnECTION = (RASBase+31);
ERROR_INVALID_SIZE = (RASBase+32);
ERROR_PORT_NOT_AVAILABLE = (RASBase+33);
ERROR_CANNOT_PROJECT_CLIENT = (RASBase+34);
ERROR_UNKNOWN = (RASBase+35);
ERROR_WRONG_DEVICE_ATTACHED = (RASBase+36);
ERROR_BAD_STRING = (RASBase+37);
ERROR_REQUEST_TIMEOUT = (RASBase+38);
ERROR_CANNOT_GET_LANA = (RASBase+39);
ERROR_NETBIOS_ERROR = (RASBase+40);
ERROR_SERVER_OUT_OF_RESOURCES = (RASBase+41);
ERROR_NAME_EXISTS_ON_NET = (RASBase+42);
ERROR_SERVER_GENERAL_NET_FAILURE = (RASBase+43);
WARNING_MSG_ALIAS_NOT_ADDED = (RASBase+44);
ERROR_AUTH_INTERNAL = (RASBase+45);
ERROR_RESTRICTED_LOGON_HOURS = (RASBase+46);
ERROR_ACCT_DISABLED = (RASBase+47);
ERROR_PASSWD_EXPIRED = (RASBase+48);
ERROR_NO_DIALIN_PERMISSION = (RASBase+49);
ERROR_SERVER_NOT_RESPONDING = (RASBase+50);
ERROR_FROM_DEVICE = (RASBase+51);
ERROR_UNRECOGNIZED_RESPONSE = (RASBase+52);
ERROR_MACRO_NOT_FOUND = (RASBase+53);
ERROR_MACRO_NOT_DEFINED = (RASBase+54);
ERROR_MESSAGE_MACRO_NOT_FOUND = (RASBase+55);
ERROR_DEFAULTOFF_MACRO_NOT_FOUND = (RASBase+56);
ERROR_FILE_COULD_NOT_BE_OPENED = (RASBase+57);
ERROR_DEVICENAME_TOO_LONG = (RASBase+58);
ERROR_DEVICENAME_NOT_FOUND = (RASBase+59);
ERROR_NO_RESPONSES = (RASBase+60);
ERROR_NO_COMMAND_FOUND = (RASBase+61);
ERROR_WRONG_KEY_SPECIFIED = (RASBase+62);
ERROR_UNKNOWN_DEVICE_TYPE = (RASBase+63);
ERROR_ALLOCATING_MEMORY = (RASBase+64);
ERROR_PORT_NOT_CONFIGURED = (RASBase+65);
ERROR_DEVICE_NOT_READY = (RASBase+66);
ERROR_READING_INI_FILE = (RASBase+67);
ERROR_NO_ConnECTION = (RASBase+68);
ERROR_BAD_USAGE_IN_INI_FILE = (RASBase+69);
ERROR_READING_SECTIONNAME = (RASBase+70);
ERROR_READING_DEVICETYPE = (RASBase+71);
ERROR_READING_DEVICENAME = (RASBase+72);
ERROR_READING_USAGE = (RASBase+73);
ERROR_READING_MAXConnECTBPS = (RASBase+74);
ERROR_READING_MAXCARRIERBPS = (RASBase+75);
ERROR_LINE_BUSY = (RASBase+76);
ERROR_VOICE_ANSWER = (RASBase+77);
ERROR_NO_ANSWER = (RASBase+78);
ERROR_NO_CARRIER = (RASBase+79);
ERROR_NO_DIALTONE = (RASBase+80);
ERROR_IN_COMMAND = (RASBase+81);
ERROR_WRITING_SECTIONNAME = (RASBase+82);
ERROR_WRITING_DEVICETYPE = (RASBase+83);
ERROR_WRITING_DEVICENAME = (RASBase+84);
ERROR_WRITING_MAXConnECTBPS = (RASBase+85);
ERROR_WRITING_MAXCARRIERBPS = (RASBase+86);
ERROR_WRITING_USAGE = (RASBase+87);
ERROR_WRITING_DEFAULTOFF = (RASBase+88);
ERROR_READING_DEFAULTOFF = (RASBase+89);
ERROR_EMPTY_INI_FILE = (RASBase+90);
ERROR_AUTHENTICATION_FAILURE = (RASBase+91);
ERROR_PORT_OR_DEVICE = (RASBase+92);
ERROR_NOT_BINARY_MACRO = (RASBase+93);
ERROR_DCB_NOT_FOUND = (RASBase+94);
ERROR_STATE_MACHINES_NOT_STARTED = (RASBase+95);
ERROR_STATE_MACHINES_ALREADY_STARTED = (RASBase+96);
ERROR_PARTIAL_RESPONSE_LOOPING = (RASBase+97);
ERROR_UNKNOWN_RESPONSE_KEY = (RASBase+98);
ERROR_RECV_BUF_FULL = (RASBase+99);
ERROR_CMD_TOO_LONG = (RASBase+100);
ERROR_UNSUPPORTED_BPS = (RASBase+101);
ERROR_UNEXPECTED_RESPONSE = (RASBase+102);
ERROR_INTERACTIVE_MODE = (RASBase+103);
ERROR_BAD_CALLBACK_NUMBER = (RASBase+104);
ERROR_INVALID_AUTH_STATE = (RASBase+105);
ERROR_WRITING_INITBPS = (RASBase+106);
ERROR_INVALID_WIN_HANDLE = (RASBase+107);
ERROR_NO_PASSWORD = (RASBase+108);
ERROR_NO_USERNAME = (RASBase+109);
ERROR_CANNOT_START_STATE_MACHINE = (RASBase+110);
ERROR_GETTING_COMMSTATE = (RASBase+111);
ERROR_SETTING_COMMSTATE = (RASBase+112);
ERROR_COMM_FUNCTION = (RASBase+113);
ERROR_CONFIGURATION_PROBLEM = (RASBase+114);
ERROR_X25_DIAGNOSTIC = (RASBase+115);
ERROR_TOO_MANY_LINE_ERRORS = (RASBase+116);
ERROR_OVERRUN = (RASBase+117);
ERROR_ACCT_EXPIRED = (RASBase+118);
ERROR_CHANGING_PASSWORD = (RASBase+119);
ERROR_NO_ACTIVE_ISDN_LINES = (RASBase+120);
ERROR_NO_ISDN_CHANNELS_AVAILABLE = (RASBase+121);

Const
RASCS_OpenPort = 0;
RASCS_PortOpened = 1;
RASCS_ConnectDevice = 2;
RASCS_DeviceConnected = 3;
RASCS_AllDevicesConnected = 4;
RASCS_Authenticate = 5;
RASCS_AuthNotify = 6;
RASCS_AuthRetry = 7;
RASCS_AuthCallback = 8;
RASCS_AuthChangePassword = 9;
RASCS_AuthProject = 10;
RASCS_AuthLinkSpeed = 11;
RASCS_AuthAck = 12;
RASCS_ReAuthenticate = 13;
RASCS_Authenticated = 14;
RASCS_PrepareForCallback = 15;
RASCS_WaitForModemReset = 16;
RASCS_WaitForCallback = 17;

RASCS_Interactive = RASCS_Paused;
RASCS_RetryAuthentication = RASCS_Paused + 1;
RASCS_CallbackSetByCaller = RASCS_Paused + 2;
RASCS_PasswordExpired = RASCS_Paused + 3;

RASCS_Connected = RASCS_Done;
RASCS_DisConnected = RASCS_Done + 1;

Type
{ Identifies an active RAS Connection. (See RasConnectEnum) }
PRASConn = ^TRASConn;
TRASConn = record
dwSize: DWORD;
rasConn: HRASConn;
szEntryName: Array[0..RAS_MaxEntryName] Of Char;
szDeviceType : Array[0..RAS_MaxDeviceType] Of Char;
szDeviceName : Array [0..RAS_MaxDeviceName] of char;
end;

PRASConnStatus = ^TRASConnStatus;
TRASConnStatus = Record
dwSize: LongInt;
rasConnstate: Word;
dwError: LongInt;
szDeviceType: Array[0..RAS_MaxDeviceType] Of Char;
szDeviceName: Array[0..RAS_MaxDeviceName] Of Char;
End;

PRASDIALEXTENSIONS= ^TRASDIALEXTENSIONS;
TRASDIALEXTENSIONS= Record
dwSize: DWORD;
dwfOptions: DWORD;
hwndParent: HWnd;
reserved: DWORD;
end;

PRASDialParams = ^TRASDialParams;
TRASDialParams = Record
dwSize: DWORD;
szEntryName: Array[0..RAS_MaxEntryName] Of Char;
szPhoneNumber: Array[0..RAS_MaxPhoneNumber] Of Char;
szCallbackNumber: Array[0..RAS_MaxCallbackNumber] Of Char;
szUserName: Array[0..UNLEN] Of Char;
szPassword: Array[0..PWLEN] Of Char;
szDomain: Array[0..DNLEN] Of Char;
end;

PRASEntryName = ^TRASEntryName;
TRASEntryName = Record
dwSize: LongInt;
szEntryName: Array[0..RAS_MaxEntryName] Of Char;
// Reserved: Byte;
End;

TRASPPPIP=record //活动连接的动态IP地址信息 add by LDS
dwSize:DWORD;
dwError:DWORD;
szIpAddress:array[0..RAS_MaxIpAddress] of char;
end;

Function RasDial(
lpRasDialExtensions : PRASDIALEXTENSIONS ; // pointer to function extensions data
lpszPhonebook: PChar; // pointer to full path and filename of phonebook file
lpRasDialParams : PRASDIALPARAMS; // pointer to calling parameters data
dwNotifierType : DWORD; // specifies type of RasDial event handler
lpvNotifier: DWORD; // specifies a handler for RasDial events
var rasConn: HRASConn // pointer to variable to receive connection handle
): DWORD; stdcall;

function RasEnumConnections(RASConn: PrasConn; { buffer to receive Connections data }
var BufSize: DWord; { size in bytes of buffer }
var Connections: DWord { number of Connections written to buffer }
): LongInt; stdcall;

Function RasEnumEntries (
reserved: PChar; // reserved, must be NULL
lpszPhonebook: PChar ; // pointer to full path and filename of phonebook file
lprasentryname: PRASENTRYNAME ; // buffer to receive phonebook entries
var lpcb : DWORD;// size in bytes of buffer
var lpcEntries : DWORD// number of entries written to buffer
) : DWORD; stdcall;

function RasGetConnectStatus(RASConn: hrasConn; { handle to Remote Access Connection of interest }
RASConnStatus: PRASConnStatus { buffer to receive status data }
): LongInt; stdcall;

function RasGetErrorString(ErrorCode: DWord; { error code to get string for }
szErrorString: PChar; { buffer to hold error string }
BufSize: DWord { sizeof buffer }
): LongInt; stdcall;

function RasHangUp(RASConn: hrasConn { handle to the Remote Access Connection to hang up }
): LongInt; stdcall;

function RasGetEntryDialParams(
lpszPhonebook:PChar; // pointer to the full path and filename of the phonebook file
VAR lprasdialparams:TRASDIALPARAMS; // pointer to a structure that receives the connection parameters
VAR lpfPassword : BOOL // indicates whether the user's password was retrieved
): DWORD; stdcall;

function RasGetProjectionInfo( //获取指定的活动的拨号连接的动态IP地址信息
hrasconn:HRasConn; //
rasprojection:DWORD;//RAS连接类型 //=RASP_PPPIP=$8021
var lpprojection:TRASPPPIP;//接受动态IP信息的地址
var lpcb:DWORD //=sizeof(TRASPPPIP)
):DWORD;stdcall; //zero:succeed

implementation

const
RAS_DLL = 'RASAPI32.dll';

function RasDial; external RAS_DLL name 'RasDialA';
function RasEnumConnections; external RAS_DLL name 'RasEnumConnectionsA';
function RasEnumEntries; external RAS_DLL name 'RasEnumEntriesA';
function RasGetConnectStatus; external RAS_DLL name 'RasGetConnectStatusA';
function RasGetErrorString; external RAS_DLL name 'RasGetErrorStringA';
function RasHangUp; external RAS_DLL name 'RasHangUpA';
function RasGetEntryDialParams; external RAS_DLL name 'RasGetEntryDialParamsA';
function RasGetProjectionInfo;external RAS_DLL name 'RasGetProjectionInfoA' //add by LDS
end.

 
很难看懂
 
多人接受答案了。
 
后退
顶部