Click here to Skip to main content
Click here to Skip to main content

TAPI 3.0 Application development using C#.NET

By , 15 Jul 2005
 

Sample Image

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);
            ia[i]=ln;
            if(ln!=null)
            {
                comboBox1.Items.Add(ia[i].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!

Points of Interest

My interest is in developing more and more TAPI 3.0 applications using .NET as the platform. I am also interested in J2EE application development. My other areas of interest are:

  • VC++
  • Crystal Reports

and many other thing in my reach.

History

Latest revised version. This is the first release of this code so if you do have any suggestions they are always welcomed by me.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

devang_bison
Web Developer
India India
Member
Hi,I am 21 year old student of information technology.I am interested to develop Computer telephony integeration softwares. I am also interested in deploying crystal reports, Directx programming and device driver implementation using VC++.Currently i am pursuing my b.tech(i.t.) degree at Nirma Institute of Technology,Gujarat(india).
Skills : vb.net,vc#.net,VC++(MFC)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 3memberMorteza Azizi16hrs 56mins ago 
Thanks
QuestionHow the SSTP/PPTP/L2TP will work?memberMember 1001650928 Apr '13 - 20:01 
Hi devang,
 
how the above code works if i dont have SSTP/PPTP/L2TP? from where can i download SSTP/PPTP/L2TP?
Any help would be highly appreciated..
 
Thanks,
Sai Krishna
QuestionNeed Testing StepsmemberAmjad_pk27 Mar '13 - 3:26 
Kindly tell me how i can test this solution.
 
Is there any device used or directly connect telephone line into PC.
 
This is my email husamjad@gmail.com
QuestionGetting Same ErrormemberChintan Dalwadi7 Feb '13 - 20:29 
why when I try to register my modem this error appears "There is no connection for this connection ID (Exception from HRESULT: 0x80040004 (OLE_E_NOCONNECTION))"
melisaAngelNegro 26 Feb '11 - 15:32
 
I'm trying to register the HDAUDIO Soft Data Fax Modem with SmartCP but i got the error message "There is no connection for this connection ID (Exception from HRESULT: 0x80040004 (OLE_E_NOCONNECTION))" I already connected the phone wire in my laptop, why I dont have connection?

thanks for every help you can provide me

-Melisa
Reply·View Thread·Permalink·Bookmark
 
Solution
Andrii Muza 8 Apr '11 - 4:10
 

Set Isolated to False for Interop.TAPI3Lib and use .NET Framework 2.0.
AnswerRe: Getting Same Errormemberfarzad zaheri27 Mar '13 - 3:58 
i set isolated to false and use .netframework 2 but i still simillar problem
what can i do?
QuestionHow to detect Caller Id using TAPI? [modified]memberSabah u Din Irfan4 Feb '13 - 4:23 
Hi,
 
How Can I detect a caller id using TAPI? Can you please provide a code snip for this? I am trying to connect to BCM 50 telephony exchange.
 
Your help will be appreciated.
 
Kind Regards,
Sabah

modified 6 Feb '13 - 17:43.

GeneralMy vote of 4memberWeylandYutani9 Dec '12 - 20:18 
Something you skipped, but excellent. For example: "...then right click on the solution file in Solution Explorer. This will open a dialog..." fail...
QuestionWindows 8memberEasygoing19 Nov '12 - 0:38 
hi,
 
is this running under windows8? I tried you examplte, but the line for my Telephone-System is not found. Under Windwos 7 it's fine!
 
Any ideas?
 
Thanks
Best Regards
QuestionRe: Windows 8memberafaz12 Jan '13 - 18:27 
the same is here...
any kind of help will be appreciated!
Nothing is impossible

QuestionCaller IDmemberMember 844370130 Oct '12 - 14:58 
How can I get the caller ID? I tried changing the RegisterCallNotifications to TAPIMEDIATYPE_DATAMODEM. Is the CIS_CALLERIDNUMBER returned in the TE_CALLSTATE?
AnswerRe: Caller IDmemberEasygoing19 Nov '12 - 0:39 
hi,
 
try this:
 
TAPI3Lib.ITCallStateEvent a = (TAPI3Lib.ITCallStateEvent)eobj;
                        TAPI3Lib.ITCallInfo b = a.Call;
...
case TAPI3Lib.CALL_STATE.CS_OFFERING:
                                string calleridNr1 = b.get_CallInfoString(CALLINFO_STRING.CIS_CALLERIDNUMBER);

Questionincoming call? [modified]memberEasygoing14 Oct '12 - 23:26 
Hi,
 
thanks for this great example. But how do i get the Phone-No from the
incoming call?
 
public void Event(TAPI3Lib.TAPI_EVENT te, object eobj)
{
  switch (te)
  {
     case TAPI3Lib.TAPI_EVENT.TE_CALLNOTIFICATION:
     // ?????????????????????????????????
 
Thanks
best regards
rene

modified 16 Oct '12 - 9:06.

Questionwhen i try to install and done....membercsharpcomeintome20 Sep '12 - 21:33 
THIS IS A FAKE PROGRAM AND FAKE INSTALLATION!!!
 
C:\Users\your username\Desktop but not exe reference file!!!
AnswerRe: when i try to install and done....memberHassanMirza1 Dec '12 - 8:26 
Its default path after installation is not right, just give the exact path of .exe file from Installed folder.
Bugand then its....membercsharpcomeintome20 Sep '12 - 4:09 
<big>VERY VERY SLOW APPLICATION!!! DON'T GET OR DOWNLOAD IT! UNTIL FIXED!</big>
Bughe's not reply!membercsharpcomeintome20 Sep '12 - 4:08 
ehehehe! he is a genius but won't help us! remove this code plz until it is commented detaily! Not work! And number of lines is limited by 10! I've 68 lines. And how can i make call???! This is very very bugly!!!!
QuestionHRESULT 0x80040007 OLE_E_BLANKmemberdnyan8613 Sep '12 - 3:22 
hi devang ,
please bhai reply,
we are getting lots of exceptions in it.....
also not enough help available on web too. :(
QuestionNot work!!memberCrisLoveStefy2 Sep '12 - 21:22 
When i compile this project, ok. When i run it the interface not appear?
Why? Fake source code or? Thanks!
AnswerRe: Not work!!memberCrisLoveStefy18 Sep '12 - 3:00 
Yes i really want reply to my own message, and then? f*** this message. Hey programmer is not really work Mad | :mad: ! Bad project   Dead | X| . Sorry. Thumbs Down | :thumbsdown: Thumbs Down | :thumbsdown: Thumbs Down | :thumbsdown: Thumbs Down | :thumbsdown: Thumbs Down | :thumbsdown: Thumbs Down | :thumbsdown: Thumbs Down | :thumbsdown: Thumbs Down | :thumbsdown:
QuestionDTMF digits not detectedmemberRinaldo Bonfanti Posta7 Aug '12 - 4:49 
Hello to all.
I'm trying to write an application that reads the DTMF Digits by the caller, but the event TE_DIGITEVENT does not launch the handler and will not work.
can anyone help me?
 
Thanks.
Rinaldo
Question"Com Excepiton " Please help me.....memberAvadhut Salavi9 May '12 - 23:15 
I can't disconnect the incoming call from the above program .
Along with that I write progam for playing .wav file ,but it is not properly
working.
It gives exception
 
i made bold there where I got excption .
So please send me details as early as possible
 
Thanking you,
Ganesh
avadhut.cse@gmail.com
 
//ANSWER BUTTON
private void answer_Click(object sender, System.EventArgs e)
{
ITAddress i;
i = ia[line];
bool status=false;

IEnumCall ec = ia[line].EnumerateCalls();
uint arg = 0;
ITCallInfo ici;
 
try
{
ec.Next(1, out ici, ref arg);
ITBasicCallControl m_CallControl = (TAPI3Lib.ITBasicCallControl)ici;
ITBasicCallControl2 callControl2 = ici as ITBasicCallControl2;
ITStream ist = ici as ITStream;
ITTerminal localTerm=ici as ITTerminal;
if (!reject)
{
if (callControl2 != null)
{
// request the terminal using right media type and direction
localTerm = callControl2.RequestTerminal(TapiConstants.CLSID_String_FilePlaybackTerminal, TapiConstants.TAPIMEDIATYPE_AUDIO, TERMINAL_DIRECTION.TD_CAPTURE);

// ist.Terminals;


// ist.SelectTerminal(localTerm);

// prepare to put the file name
ITMediaPlayback mediaPlayback = localTerm as ITMediaPlayback;
 
if (mediaPlayback != null)
{
try
{
// Set the filename to play
object[] fileList = { @"E:\tapi8.2\w.wav" };
mediaPlayback.PlayList = fileList;

// Select the terminal
callControl2.SelectTerminalOnCall(localTerm); //HERE IS EXCEPTION AS "COMEXCEPTION"


// Answer the call
m_CallControl.Answer();

 

// Start playback.
ITMediaControl mediaControl = localTerm as ITMediaControl;
mediaControl.Start();

 

// Assign the terminal now terminal
// m_PlayFileTerminal = localTerm;
status = true;
}
catch (Exception ep)
{
MessageBox.Show("here is exception inplaying music\n\n" + ep);
//if (Log.IsErrorEnabled)
//{
// Log.ErrorFormat("Call.ReadyPlayTerminal: *** EXCEPTION*** {0}", e);
//}
}
}

}
else
{
MessageBox.Show("All calls are rejected. Please remove 'Reject' tickmark");
m_CallControl.Disconnect(DISCONNECT_CODE.DC_REJECTED);
//ici.ReleaseUserUserInfo();
tobj.Shutdown();
initializetapi3();
registertoken[line] = tobj.RegisterCallNotifications(ia[line], true, true, TapiConstants.TAPIMEDIATYPE_DATAMODEM, 2);
MessageBox.Show("Registration token : " + registertoken[line], "Registration Succeed for line " + line);
}
}
}
catch (Exception exp)
{
MessageBox.Show("There may not be any calls to answer! \n\n" + exp, "TAPI3");
}
}
QuestionTapi aplication, problem with sending DTMF signalmemberMember 86346749 Feb '12 - 8:18 
Hi I'm trying to write an aplication that makes a modem connection and after that sends a dtmf signal. My application creates a call but it doesnt send that DTMF signal.
 
My application :
 
 
 

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
 
using TAPI3Lib;
 
namespace dialer
{
	
	public partial class MainForm : Form
	{
		private TAPIClass tapi;
		private ITAddress[] adresy = new ITAddress[10]; 
		private ITBasicCallControl polaczenie = null;
		private int wybrany = -1; 
		
		public MainForm()
		{
			InitializeComponent();
			ZainicjalizujTAPI();
		}
		
		private void ZainicjalizujTAPI()
		{
			try
			{
				
				tapi = new TAPIClass();
				tapi.Initialize();
				
				
				IEnumAddress ea = tapi.EnumerateAddresses();
				ITAddress adres;
				uint arg = 0;
				
				for(uint i = 0; i < 10; ++i)
				{
					ea.Next(1, out adres, ref arg);
					if(adres == null) break;
					adresy[i] = adres;
					listaLinii.Items.Add(adres.AddressName);
				}
			}
			catch(Exception wyj)
			{
				
				MessageBox.Show(wyj.ToString(), "Błąd!");
			}
		}
		
		
		void Button1Click(object sender, EventArgs e)
		{
			if(listaLinii.SelectedIndex < 0)
			{
				MessageBox.Show("Nie wybrano linii", "Błąd!");
				return;
			}
			
			if(polaczenie != null)
			{
				MessageBox.Show("Połączenie już istnieje", "Błąd!");
				return;
			}
			
			wybrany = listaLinii.SelectedIndex;
			
			try
			{
				polaczenie = adresy[wybrany].CreateCall("12345678",
				  TapiConstants.LINEADDRESSTYPE_PHONENUMBER,
				  TapiConstants.TAPIMEDIATYPE_DATAMODEM | TapiConstants.TAPIMEDIATYPE_AUDIO);
								  
				polaczenie.SetQOS(TapiConstants.TAPIMEDIATYPE_DATAMODEM | TapiConstants.TAPIMEDIATYPE_AUDIO, 
			  QOS_SERVICE_LEVEL.QSL_BEST_EFFORT);
				
				polaczenie.Connect(false);
			}
			catch(Exception wyj)
			{
				MessageBox.Show(wyj.ToString(), "Błąd!");
				polaczenie = null;
			}
		}
		
		void Button2Click(object sender, EventArgs e)
		{
			if(polaczenie == null) return;
			
			try
			{
				
				polaczenie.Disconnect(DISCONNECT_CODE.DC_NORMAL);
				polaczenie = null;
			}
			catch(Exception wyj)
			{
				MessageBox.Show(wyj.ToString(), "Błąd!");
			}
		}
		
		// HERE is the button responsible for sending DTMF signal (doesn't work)
		void Button3Click(object sender, EventArgs e)
		{
			if(polaczenie == null) return;
			
			try
			{
								
				ITLegacyCallMediaControl2 cmc = (ITLegacyCallMediaControl2) polaczenie;
				cmc.GenerateDigits("246", TapiConstants.LINEDIGITMODE_DTMF);
				
			}
			catch(Exception wyj)
			{
				MessageBox.Show(wyj.ToString(), "Błąd!");
			}
		}
		
		void ListaLiniiSelectedIndexChanged(object sender, EventArgs e)
		{
			
		}
	}
}
 


GeneralMy vote of 5memberemmybest1 Feb '12 - 6:06 
i must say you are good
BugApplication fail to register after some timemembersaadullah Bhutto29 Sep '11 - 5:21 
I have tried this Article and it work fine ,
but i m stucked at only one problem that when i publish this application and after few day (or in a month) the line which i register failed (Error : Failed to register at line 0) .
 
kindly help me coz i have to submit this to Client
QuestionTAPI 3 on windows 7memberMember 809297018 Jul '11 - 4:10 
Hi
 
Thanks for this sample - I managed to use it to get TAPI working correctly on a windows XP machine. However, it does not work on Windows 7. I have found a posting http://www.eggheadcafe.com/microsoft/Win32-TAPI/35879324/does-windows-7-support--tapi-23.aspx[^] that states H.323 TSP has been removed from Vista and Windows 7. What changes do you suggest I make to get it to work?
 
Many thanks in advance

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 15 Jul 2005
Article Copyright 2005 by devang_bison
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid