본문 바로가기
Delphi, RadStudio

[개발/delphi] 인터넷 연결 목록을 추적하기

by SB리치퍼슨 2012. 1. 17.
[개발/delphi] 인터넷 연결 목록을 추적하기

// d2007, JVCL 사용, TJvRas32 (PhoneBook VCL)

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;
반응형

댓글