Einzelnen Beitrag anzeigen

sonic

Registriert seit: 14. Mär 2003
30 Beiträge
 
Delphi 2006 Professional
 
#8

Re: Procedur mit Timeout aufrufen...

  Alt 12. Jul 2007, 13:18
Hallo!

Wollte nur mal den Code einfügen wie ich nun die DLL Calls aufrufe...

Delphi-Quellcode:
function TClientAdapter.ExpBeginThread(ThreadFunc: TThreadFunc; Parameter: Pointer; Timout : integer): boolean;
var
  id : LongWord;
  thread : Integer;
  wf : DWORD;
begin
  Result := false;
  if fTimeout then
  begin
    Result := false;
    exit;
  end
  else
  begin
    thread := BeginThread(nil, 0, ThreadFunc, Parameter, 0, id);
    if (thread <> INVALID_HANDLE_VALUE) then
    begin
      wf := WaitForSingleObject(thread, Timout);
      case wf of
        WAIT_OBJECT_0:
        begin
          result := True;
        end;
        WAIT_TIMEOUT :
        begin
          TerminateThread(thread, 0);
          Timeout := True;
          result := False;
        end;
        WAIT_FAILED :
        begin
          Timeout := True;
          result := False;
        end;
      end;
      CloseHandle(thread);
    end;
  end;
end;

function TClientAdapter.LibKeepAlive(Sender: TObject): ByteBool;
var
  data : LibKeepAliveData;

  function ThreadLibKeepAlive(Parameter : Pointer) : integer;
  begin
    result := 0;
    LibKeepAliveData(Parameter^).result := KeepAlive(); // DLL Call...
  end;
begin
  if ExpBeginThread(Addr(ThreadLibKeepAlive), Addr(data), gTimeout) then
    result := data.result
  else
    result := false;
end;
Mlg Mike
  Mit Zitat antworten Zitat