开发者

In Delphi 7, how can I retrieve Internet Connection names list?

Earlier I ask how can I set Internet Proxy in Windows connection.

But my problem is that if I want to set all connections, t开发者_如何学JAVAhen must be list connection names list. I search over net but I can't find any answer for this.


You're looking for RasEnumEntries function. Delphi doesn't have RAS API functions declared, but easy if you've got JVCL. The TJvRas32 component has a PhoneBook TStrings property in which available connections are populated.

Below is D2007 test code (no error checking):

const
  RAS_MaxEntryName = 256;
  RASBASE = 600;
  ERROR_BUFFER_TOO_SMALL = RASBASE + 3;
  ERROR_INVALID_SIZE = RASBASE + 32;

type
  PRasEntryName = ^TRasEntryName;
  TRasEntryName = record
    dwSize: Longint;
    szEntryName: array [0..RAS_MaxEntryName] of Char;
  end;

function RasEnumEntriesA(reserved: PChar; lpszPhonebook: PChar;
          lpRasEntryName: PRasEntryName; var lpcb: DWORD;
          var lpcEntries: DWORD): DWORD; stdcall; external 'RASAPI32.DLL';

procedure GetRasEntries(List: TStrings);
var
  RasEntryNames: array of TRasEntryName;
  Err, Size, Entries: DWORD;
  i: Integer;
begin
  List.Clear;
  SetLength(RasEntryNames, 1);
  Size := SizeOf(TRasEntryName);
  RasEntryNames[0].dwSize := Size;
  Err := RasEnumEntriesA(nil, nil, @RasEntryNames[0], Size, Entries);
  if (Err = ERROR_BUFFER_TOO_SMALL) and (Entries > 0) then begin
    Assert(Size = SizeOf(TRasEntryName) * Entries);
    SetLength(RasEntryNames, Entries);
    Err := RasEnumEntriesA(nil, nil, @RasEntryNames[0], Size, Entries);
    if Err = 0 then
      for i := 0 to Length(RasEntryNames) do
        List.Add(RasEntryNames[i].szEntryName);
  end else
    List.Add(RasEntryNames[0].szEntryName);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  GetRasEntries(ListBox1.Items);
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜