Interop.TAPI3Lib, anyway else?

Hi,

as you know, Interop.TAPI3Lib is usefull for TAPI. But it doesn't work very well. I use it in a thread, but after the 1st (in the best situations, 3th) notification, it forgets to notify my thread about the line's activities. Maybe i use it badly, or the dll is old, beacuse tyring to contact using that DLL, causes my thread to crash, so i MUST use it in a try..catch.  Does anyone have any other soltuion, for use of TAPI Help me plz.

With thanks.




Answer this question

Interop.TAPI3Lib, anyway else?

  • matteo raumer

    Introduction

    This is a C# program which will exemplify the procedure which needs to be followed while doing TAPI programming using TAPI 3.0. Hence it can also be useful for VB.NET developers seeking TAPI 3.0 sample code for .NET. Here basic knowledge about TAPI and other related terms is assumed. To have more knowledge on TAPI 3.0, contact me on my email address or refer to the help provided in MSDN.

    Background

    Hello, myself Gohel Devang M., 20 years old, Information Technology student. This is my first attempt to put some sample code on any site so if you do have any problems mail me at devang.mg@gmail.com.

    This is a sample code to interface TAPI 3.0 API using .NET platform and C# as language. So people interested in developing telephony applications using C# will find this very useful. I was inspired to do this because I was not able to find such code on this site.

    Initial steps

    The first thing you need to start working on TAPI 3.0 API is to add the references to your project. To do that first create a new project or open an existing project, then right click on the solution file in Solution Explorer. This will open a dialog box showing three tabs as below:

    Then click on Browse button and select the tapi3.dll file from your windows\system32 or windows\system directory and click OK. Then press OK in the dialog box that had popped when you select Add references from the right click popup menu of the Solution Explorer.

    Now you are ready to work with TAPI 3.0.

    Using the code

    The second thing you need to do is create the TAPI objects to initialize the TAPI 3.0 TSP (TAPI Service Providers). To have more information on TSP and what TAPI is all about, please refer to help provided in the MSDN .NET documentation. The code below is a declaration of the TAPI object and addresses the interfaces that will hold the addresses which are responsible for call handling, and basic call control interface which will hold the reference to the object that will be responsible for handling basic operations of the call.

    private TAPIClass tobj;
    private ITAddress[] ia=new TAPI3Lib.ITAddress[10];
    private ITBasicCallControl bcc;

    The code below is responsible for initializing a TAPI object so that it can be used by our application. The main functions are:

    • Initialize() will initialize TAPI.
    • EnumerateAddresses() will give the list of available TSPs.
    void initializetapi3()
    {
      try
      {
        tobj = new TAPIClass();
        tobj.Initialize();
        IEnumAddress ea=tobj.EnumerateAddresses();
        ITAddress ln;
        uint arg3=0;
        lines=0;
      
        cn=new callnotification();
        cn.addtolist=new callnotification.listshow(this.status);
        tobj.ITTAPIEventNotification_Event_Event+= new 
          TAPI3Lib.ITTAPIEventNotification_EventEventHandler(cn.Event);
        tobj.EventFilter=(int)(TAPI_EVENT.TE_CALLNOTIFICATION|
          TAPI_EVENT.TE_DIGITEVENT|
          TAPI_EVENT.TE_PHONEEVENT|
          TAPI_EVENT.TE_CALLSTATE|
          TAPI_EVENT.TE_GENERATEEVENT|
          TAPI_EVENT.TE_GATHERDIGITS|
          TAPI_EVENT.TE_REQUEST);
      
        for(int i=0;i<10;i++)
        {
          ea.Next(1,out ln,ref arg3);
          iaIdea=ln;
          if(ln!=null)
          {
            comboBox1.Items.Add(iaIdea.AddressName);
            lines++;
          }
          else
            break;
        }
      }
      catch(Exception e)
      {
        MessageBox.Show(e.ToString());
      }
    }

    The code below is responsible for registering incoming calls so that they can be handled by our application. For that you need to select the line on which you want to receive calls and press the Register button.

    try
    {
      registertoken[line]=tobj.RegisterCallNotifications(ia[line],
             true,true,TapiConstants.TAPIMEDIATYPE_AUDIO,2);  
      MessageBox.Show("Registration token : "+ 
             registertoken[line], 
             "Registration Succeed for line "+line);
    }
    catch(Exception ein)
    {
      MessageBox.Show("Failed to register on line "+line,"Registration for calls");
    }

    The class given below is to be added depending upon your TAPI event handling requirements. This is specially designed according to the requirements of the application.

    class callnotification:TAPI3Lib.ITTAPIEventNotification
    {
      public delegate void listshow(string str);
      public listshow addtolist;
      
      public void Event(TAPI3Lib.TAPI_EVENT te,object eobj)
      {
        switch(te)
        {
          case TAPI3Lib.TAPI_EVENT.TE_CALLNOTIFICATION:
            addtolist("call notification event has occured");
            break;
          case TAPI3Lib.TAPI_EVENT.TE_DIGITEVENT:
            TAPI3Lib.ITDigitDetectionEvent dd = 
              (TAPI3Lib.ITDigitDetectionEvent)eobj;
            addtolist("Dialed digit"+dd.ToString());
            break;
          case TAPI3Lib.TAPI_EVENT.TE_GENERATEEVENT:
            TAPI3Lib.ITDigitGenerationEvent dg = 
               (TAPI3Lib.ITDigitGenerationEvent)eobj;
            MessageBox.Show("digit dialed!");
            addtolist("Dialed digit"+dg.ToString());
            break;
          case TAPI3Lib.TAPI_EVENT.TE_PHONEEVENT:
            addtolist("A phone event!");
            break;
          case TAPI3Lib.TAPI_EVENT.TE_GATHERDIGITS:
            addtolist("Gather digit event!");
            break;
          case TAPI3Lib.TAPI_EVENT.TE_CALLSTATE:
            TAPI3Lib.ITCallStateEvent a= 
               (TAPI3Lib.ITCallStateEvent)eobj;
            TAPI3Lib.ITCallInfo b=a.Call;
          switch(b.CallState)
          {
            case TAPI3Lib.CALL_STATE.CS_INPROGRESS:
              addtolist("dialing");
              break;
            case TAPI3Lib.CALL_STATE.CS_CONNECTED:
              addtolist("Connected");
              break;
            case TAPI3Lib.CALL_STATE.CS_DISCONNECTED:
              addtolist("Disconnected");
              break;
            case TAPI3Lib.CALL_STATE.CS_OFFERING:
              addtolist("A party wants to communicate with you!");
              break;
            case TAPI3Lib.CALL_STATE.CS_IDLE:
              addtolist("Call is created!");
              break;
          }
          break;
        }
      }
    }

    How to handle H.323 or IP calls

    To do IP calls or H.323 calls, you need to make a checkbox named H.323 call(IP call) enabled and enter the IP address of the destination and press the Call button. Otherwise it will not succeed in calling to the remote destination. To receive H.323 calls or IP calls, you need to first register on the line on which you want to receive IP calls and check the checkbox named h.323 call(IP call).

    How to answer an incoming call

    The incoming calls will give notification in the call status area. Then according to whether you want to accept or reject the call, you check the checkbox named Reject to reject incoming calls, and press Answer or simply press Disconnect. To accept calls, do not check Reject checkbox and simply press Answer button which will connect to the call.

    How to transfer a call

    To transfer a call, first there should be one active call existing. Then you can specify the address to which the call is to be transferred to, as shown in the figure:

    Here I have specified the internet address since the call was an IP call. To provide this functionality, there is one function in IBasicCallControl named BlindTransfer(String transfferaddress). Refer the MSDN documents for more information on that!

    devang_bison

    forworded



  • sprayer

    I am currently creating a smart devices program in visual studio .NET and using C# and TAPI.
    However, I got the problem in the first step, hope you can give me some advices to start my program.
    (I did include TAPI3 as reference from windows/system32)
    The error I got as follow:
    using TAPI3Lib;
    namespace testTAPI
    {
    public partial class Form1 : Form
    {
    private TAPIClass tobj;
    public Form1()
    {
    tobj = new TAPIClass(); <- COM object with CLSID '{21D6D48E-A88B-11D0-83DD-00AA003CCABD}'
    cannot be created due to the following error: Class not registered .
    :
    }
    }
    }
    Can TAPI3Lib work under smart devices or I need to use another version
    Can TAPI3Lib detect searching, error message .... (error handling)
    This is my questions hope u can help me on this.
    Thanks for your time



  • Alekos66

    Very good!

    Thank you!


  • Interop.TAPI3Lib, anyway else?