Subversion Repositories calllib

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. library MakeCall;
  2.  
  3. uses
  4.   SysUtils,
  5.   hbTAPI;
  6.  
  7. {$R *.res}
  8.  
  9. function GetTapiDevices(buf: PAnsiChar): integer; stdcall;
  10. var
  11.   mTapiLine: TTapiLine;
  12.   len: Integer;
  13.   s: string;
  14. begin
  15.   mTapiLine := TTapiLine.Create(nil);
  16.   try
  17.     try
  18.       mTapiLine.Active := false;
  19.       s := mTapiLine.DeviceList.Text;
  20.       len := Length(s);
  21.       if buf <> nil then
  22.       begin
  23.         FillChar(buf^, len+1{NUL}, 0);
  24.         StrPCopy(buf, s);
  25.         result := 0;
  26.       end;
  27.       result := len+1{NUL};
  28.     except
  29.       result := -1;
  30.     end;
  31.   finally
  32.     FreeAndNil(mTapiLine);
  33.   end;
  34. end;
  35.  
  36. function Call(phoneNumber: PAnsiChar; deviceId: integer): integer; stdcall;
  37. var
  38.   mTapiLine: TTapiLine;
  39. begin
  40.   mTapiLine := TTapiLine.Create(nil);
  41.   try
  42.     mTapiLine.Active := false;
  43.     mTapiLine.CallParams.Flags := 0;
  44.     mTapiLine.DeviceID := deviceId;
  45.     mTapiLine.Active := true;
  46.     if not mTapiLine.Active then
  47.     begin
  48.       // Usually "TAPI device not available"
  49.       result := -1;
  50.       exit;
  51.     end;
  52.     try
  53.       mTapiLine.MakeCall(AnsiString(phoneNumber));
  54.     except
  55.       // This can tappen when the headset is active, so the line is busy
  56.       result := -2;
  57.       exit;
  58.     end;
  59.     result := 0;
  60.   finally
  61.     FreeAndNil(mTapiLine);
  62.   end;
  63. end;
  64.  
  65. exports
  66.   Call name 'MakeCall',
  67.   GetTapiDevices;
  68.  
  69. begin
  70. end.
  71.