Calling TAPI functions directly

hbTapi Components and in particular the Enterprise Edition gives you the ability to call TAPI functions directly. This enables you to extend the functionality. ThbTapiLine and ThbTapiPhone provide several properties and events like Handle, OnTapiReply and OnTapiMessage to give you a low-level access to TAPI.

The following example shows how to call a simple TAPI function like lineAnswerCall. The function is called using the call's handle and a sample text as user user information. The lineAnswer function returns an error or positive result code that means the function will complete asynchron. The result is catched within the OnTapiReply event. The OnTapiMessage can be used also.

procedure TForm1.Button1Click(Sender: TObject);
var sUserUserInfo: String; rc: LongInt;
begin
  sUserUserInfo := 'Hello World';

  if hbTapiLine1.Calls.Count > 0 then
  begin
    rc := lineAnswer(hbTapiLine1.Calls[0].Handle, PChar(sUserUSerInfo), length(sUserUserInfo)+1);
    if rc < 0 then
       MessageDlg('AnswerCall failed! ' + LineErrToStr(rc), mtError, [mbOk], 0)
    else // rc > 0; function will be completed asynchronous
      FAnswerRequestID := rc; // store the RequestID
  end;
end;

procedure TForm1.hbTapiLine1TapiReply(Sender: TObject; RequestID, ReplyCode: Cardinal);
begin
  if DWROD(RequestID) = FAnswerRequestID then
  begin
    if ReplyCode = 0 then
      MessageDlg('AnswerCall succeeded!', mtInformation, [mbOk], 0)
    else
      MessageDlg('AnswerCall failed! ' + LineErrToStr(ReplyCode), mtError, [mbOk], 0)
  end;
end;

Properties and Events that are often used in context of TAPI functions are:

 

 

Properties

Events

ThbTapiLine

 

DeviceID
Handle
LineApp

 

OnTapiReply
OnTapeMessage

ThbTapiAddress

 

AddressID

 

 

ThbTapiCall

 

Line
Handle

 

 

ThbTapiPhone

 

DeviceID
Handle
PhoneApp

 

OnTapiReply
OnTapeMessage

See also

The Synchronous / Asynchronous Model