Einzelnen Beitrag anzeigen

Benutzerbild von Sharky
Sharky

Registriert seit: 29. Mai 2002
Ort: Frankfurt
8.251 Beiträge
 
Delphi 2006 Professional
 
#10

Re: Message wenn sich die IP einer NIC ändert?

  Alt 28. Apr 2006, 13:17
Hai ihr zwei,

ich habe das ganze jetzt mal so gemacht und es scheint zu gehen.
Allerdings werde ich mir auch noch mal ansehen wie das ganze in einem Thread aussehen würde.

Delphi-Quellcode:
  private
    _AddrChangeEventHandle: THandle;
    procedure CreateNotifyEvent;
  public
    { Public-Deklarationen }

  end;

var
  DemoForm: TDemoForm;

implementation

{$R *.dfm}

function NotifyAddrChange(out Handle: THANDLE;
  const Overlapped: OVERLAPPED): DWORD; stdcall; external 'Iphlpapi.dll';

procedure TDemoForm.FormCreate(Sender: TObject);
begin
  _AddrChangeEventHandle := CreateEvent(NIL, FALSE, FALSE, NIL);
  CreateNotifyEvent;
end;

procedure TDemoForm.CreateNotifyEvent;
var
  NotifyHandle: Cardinal;
  Overlapped: _OVERLAPPED;
  NotifyResult: Cardinal;
begin
  Overlapped.hEvent := _AddrChangeEventHandle;
  NotifyResult := NotifyAddrChange(NotifyHandle, Overlapped);
  if not ((NotifyResult = NO_ERROR) or (NotifyResult = ERROR_IO_PENDING)) then
  begin
    RaiseLastOSError;
  end;
end;

procedure TDemoForm.FormDestroy(Sender: TObject);
begin
  CloseHandle(_AddrChangeEventHandle);
end;

procedure TDemoForm.Timer1Timer(Sender: TObject);
begin
  if (WaitForSingleObject(_AddrChangeEventHandle, 0) = WAIT_OBJECT_0) then
  begin
    ShowMessage('IP wurde geändert.');
    CreateNotifyEvent;
  end;
end;
Stephan B.
  Mit Zitat antworten Zitat