⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adrasutl.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 3 页
字号:
procedure LoadRasDlgDLL;
begin
  if (RasDlgModule = 0) then begin
    RasDlgModule := LoadLibrary(RasDlgDLL);
    if (RasDlgModule = 0) then
      Exit;
  end;
  @RasDialDlg := GetProcAddress(RASDlgModule, 'RasDialDlgA');
  @RasMonitorDlg := GetProcAddress(RASDlgModule, 'RasMonitorDlgA');
  @RasPhonebookDlg := GetProcAddress(RASDlgModule, 'RasPhonebookDlgA');
end;

function AdRasString(const Str : string) : PChar;
  {returns nil pointer if string is empty}
begin
  if (Str <> '') then
    Result := PChar(Str)
  else
    Result := nil;
end;

function AdRasPhoneBook(const PhoneBook : string) : PChar;
  {return nil pointer if not Windows NT}
begin
  if (AdRasPlatFormID = VER_PLATFORM_WIN32_NT) and (PhoneBook <> '') then
    Result := AdRasString(PhoneBook)
  else
    Result := nil;
end;

function AdDialExtensions(PDialExtensions : PRasDialExtensions
                          ) : PRasDialExtensions;
  {return nil pointer if not Windows NT}
begin
  if (AdRasPlatFormID = VER_PLATFORM_WIN32_NT) then
    Result := PDialExtensions
  else
    Result := nil;
end;


{ RASAPI functions }
function AdRasDial(PDialExtensions : PRasDialExtensions;
                   const Phonebook : string;
                   PDialParams : PRasDialParams;
                   NotifierType : DWord;
                   Notifier : DWord;
                   var HConn : THandle
                   ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasDial) then
    Result := RasDial(AdDialExtensions(PDialExtensions), AdRasPhoneBook(Phonebook),
      PDialParams, NotifierType, Notifier, @HConn)
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasDialDlg(const Phonebook : string;
                      const EntryName : string;
                      const PhoneNumber : string;
                      PDialDlgInfo : PRasDialDlgInfo
                      ) : Integer;
begin
  Result := ecRasFunctionNotSupported;
  LoadRasDlgDLL;
  if Assigned(RasDialDlg) then
    if RasDialDlg(AdRasPhoneBook(Phonebook), AdRasString(EntryName),
      AdRasString(PhoneNumber), PDialDlgInfo) then
        Result := PDialDlgInfo^.dwError;
end;

function AdRasMonitorDlg(const DeviceName : string;
                         PMonitorDlgInfo : PRasMonitorDlgInfo
                         ) : Integer;
begin
  Result := ecRasFunctionNotSupported;
  LoadRasDlgDLL;
  if Assigned(RasMonitorDlg) then
    if RasMonitorDlg(AdRasString(DeviceName), PMonitorDlgInfo) then
        Result := PMonitorDlgInfo^.dwError;
end;

function AdRasPhonebookDlg(const Phonebook, EntryName : string;
                           PPhonebookDlgInfo: PRasPhonebookDlgInfo
                           ) : Integer;
begin
  Result := ecRasFunctionNotSupported;
  LoadRasDlgDLL;
  if Assigned(RasPhonebookDlg) then
    if RasPhonebookDlg(AdRasPhoneBook(Phonebook), AdRasString(EntryName),
      PPhonebookDlgInfo) then
        Result := PPhonebookDlgInfo^.dwError;
end;

function AdRasEnumConnections(PConn : PRasConn;
                              var ConnSize : DWord;
                              var NumConnections : DWord
                              ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasEnumConnections) then
    Result := RasEnumConnections(PConn, ConnSize, NumConnections)
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasEnumEntries(const Phonebook : string;
                          PEntryName : PRasEntryName;
                          var EntryNameSize : DWord;
                          var NumEntries : DWord
                          ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasEnumEntries) then
    Result := RasEnumEntries(nil, AdRasPhoneBook(Phonebook), PEntryName,
      EntryNameSize, NumEntries)
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasClearConnectionStatistics(HConn : THandle) : Integer;      {!!.06}
begin                                                                    {!!.06}
  LoadRASDLL;                                                            {!!.06}
  if Assigned(RasClearConnectionStatistics) then                         {!!.06}
    Result := RasClearConnectionStatistics(HConn)                        {!!.06}
  else                                                                   {!!.06}
    Result := ecRasFunctionNotSupported;                                 {!!.06}
end;                                                                     {!!.06}

function AdRasGetConnectionStatistics(HConn : THandle;                   {!!.06}
                                      PStatistics : PRasStatistics       {!!.06}
                                      ) : Integer;                       {!!.06}
begin                                                                    {!!.06}
  LoadRASDLL;                                                            {!!.06}
  if Assigned(RasGetConnectionStatistics) then                           {!!.06}
    Result := RasGetConnectionStatistics(HConn, PStatistics)             {!!.06}
  else                                                                   {!!.06}
    Result := ecRasFunctionNotSupported;                                 {!!.06}
end;                                                                     {!!.06}

function AdRasGetConnectStatus(HConn : THandle;
                               PConnStatus : PRasConnStatus
                               ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasGetConnectStatus) then
    Result := RasGetConnectStatus(HConn, PConnStatus)
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasGetErrorString(ErrorCode : Integer
                             ) : string;
var
  ErrorStr : array[0..RasMaxError] of Char;
begin
  FillChar(ErrorStr, SizeOf(ErrorStr), #0);
  LoadRASDLL;
  if (ErrorCode = ecRasFunctionNotSupported) or not Assigned(RasGetErrorString) then
    StrPCopy(ErrorStr, 'Function not Supported')
  else
    RasGetErrorString(ErrorCode, ErrorStr, SizeOf(ErrorStr));
  Result := StrPas(ErrorStr);
end;

function AdRasHangup(HConn : THandle
                     ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasHangup) then
    Result := RasHangup(HConn)
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasGetEntryDialParams(const Phonebook : string;
                                 PDialParams : PRasDialParams;
                                 var GotPassword : Boolean
                                 ) : Integer;
var
  GotPWBool : Bool;
begin
  LoadRASDLL;
  if Assigned(RasGetEntryDialParams) then begin
    Result := RasGetEntryDialParams(AdRasPhoneBook(Phonebook), PDialParams,
      GotPWBool);
    GotPassword := GotPWBool;
  end else
    Result := ecRasFunctionNotSupported;
end;

function AdRasSetEntryDialParams(const Phonebook : string;
                                 PDialParams : PRasDialParams;
                                 RemovePassword : Boolean
                                 ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasSetEntryDialParams) then
    Result := RasSetEntryDialParams(AdRasPhoneBook(Phonebook), PDialParams,
      Bool(RemovePassword))
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasCreatePhonebookEntry(HWnd : THandle;
                                   const PhoneBook : string
                                   ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasCreatePhonebookEntry) then
    Result := RasCreatePhonebookEntry(HWnd, AdRasPhoneBook(Phonebook))
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasEditPhonebookEntry(HWnd : THandle;
                                 const Phonebook, EntryName : string
                                 ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasEditPhonebookEntry) then
    Result := RasEditPhonebookEntry(HWnd, AdRasPhoneBook(Phonebook),
      PChar(EntryName))  {let RAS provide error code if EntryName not valid}
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasDeleteEntry(const Phonebook, EntryName : string
                          ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasDeleteEntry) then
    Result := RasDeleteEntry(AdRasPhoneBook(Phonebook), PChar(EntryName))
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasRenameEntry(const Phonebook, EntryOld, EntryNew : string
                          ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasRenameEntry) then
    Result := RasRenameEntry(AdRasPhoneBook(Phonebook),
      PChar(EntryOld), PChar(EntryNew))
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasEnumDevices(PDeviceInfo : PRasDeviceInfo;
                          var DeviceInfoSize : DWord;
                          var NumDevices : DWord
                          ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasEnumDevices) then
    Result := RasEnumDevices(PDeviceInfo, DeviceInfoSize, NumDevices)
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasGetCountryInfo(PCountryInfo : PRasCountryInfo;
                             var CountryInfoSize : DWord
                             ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasGetCountryInfo) then
    Result := RasGetCountryInfo(PCountryInfo, CountryInfoSize)
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasGetEntryProperties(const Phonebook, EntryName : string;
                                 PEntry : PRasEntry;
                                 var EntrySize : DWord;
                                 PDeviceInfo : PTapiConfigRec;           {!!.06}
                                 var DeviceInfoSize : DWord
                                 ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasGetEntryProperties) then
    Result := RasGetEntryProperties(AdRasPhoneBook(Phonebook),
      PChar(EntryName), PEntry, EntrySize, PDeviceInfo, DeviceInfoSize)
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasSetEntryProperties(const Phonebook, EntryName : string;
                                 PEntry : PRasEntry;
                                 var EntrySize : DWord;
                                 PDeviceInfo : PTapiConfigRec;           {!!.06}
                                 var DeviceInfoSize : DWord
                                 ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasSetEntryProperties) then
    Result := RasSetEntryProperties(AdRasPhoneBook(Phonebook),
      PChar(EntryName), PEntry, EntrySize, PDeviceInfo, DeviceInfoSize)
  else
    Result := ecRasFunctionNotSupported;
end;

function AdRasValidateEntryName(const Phonebook, EntryName : string
                                ) : Integer;
begin
  LoadRASDLL;
  if Assigned(RasValidateEntryName) then
    Result := RasValidateEntryName(AdRasPhoneBook(Phonebook),
      PChar(EntryName))
  else
    Result := ecRasFunctionNotSupported;
end;


initialization
  RasModule := 0;
  RasDlgModule := 0;
  VersionInfo.dwOSVersionInfoSize := SizeOf(VersionInfo);
  if GetVersionEx(VersionInfo) then
    AdRasPlatformID := VersionInfo.dwPlatformId
  else
    AdRasPlatformID := VER_PLATFORM_WIN32s;

finalization
  if (RASModule <> 0) then
    FreeLibrary(RASModule);
  if (RASDlgModule <> 0) then
    FreeLibrary(RASDlgModule);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -