
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:
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.
|
|
 |
 | windows mobile GSM conference call kashamaleel | 19:29 3 Mar '10 |
|
 |
what part of the code i have to modify for windows mobile in windows mobile its give error of COM part and zero Line found
|
|
|
|
 |
 | Avaya Ip Office Jan Foster | 5:08 3 Mar '10 |
|
 |
Hi
I am trying to use your application on the Avaya office. I ran your dev app and it lets me register the line but will not create a call or answer. The status window shows the activity such as when I pick up the phone and dial manually. Can you help?
|
|
|
|
 |
 | Error Uninitialized object jalalx | 23:36 20 Feb '10 |
|
 |
Hi! Thanks for your good program! Why I get following error while trying to redial? Uninitialized object (Exception from HRESULT: 0x80040007 (OLE_E_BLANK))While(I.IsAlive==true) Try(Happiness);
|
|
|
|
 |
 | Conference call TjaartV | 1:49 16 Feb '10 |
|
 |
I'm desperately looking for a code example for handling a conference call. I'm able to successfully create a conference call but when the last person disconnects from a 3 party conference call the call state I'm getting back through TAPI 3 from my PABX is "Disconnected".
Please help with an example
Thanks
|
|
|
|
 |
 | Play voice via H323 Mahyar_Habibpour | 9:25 24 Oct '09 |
|
 |
I can play a sound via mnodem by this code:
private void btnPlay_Click(object sender, EventArgs e) { Object[] playList = { "C:\\houston 8kHz Mono 8.wav" }; ITTerminal PLyTerminal= bcc.RequestTerminal(TAPI3Lib.TapiConstants.CLSID_String_FilePlaybackTerminal, TapiConstants.TAPIMEDIATYPE_MULTITRACK, TERMINAL_DIRECTION.TD_CAPTURE); ITMediaPlayback MediaPlay=(ITMediaPlayback)PLyTerminal; MediaPlay.PlayList = playList; ITMediaControl MediaControl = (ITMediaControl)MediaPlay; bcc.SelectTerminalOnCall(PLyTerminal); MediaControl.Start(); }
but i need play/hear sound via H323. how?
|
|
|
|
 |
 | Caller ID? justaBystander | 18:54 28 Jul '09 |
|
 |
Hi,
I'm wondering how I can get the caller ID of the caller (like the phone number). Great article btw.
Thanks.
|
|
|
|
 |
 | I can hear the voice but the other side party cannot hear my voice vk12377 | 4:06 7 Jul '09 |
|
 |
I can hear the voice but the other side party cannot hear my voice. .I am using Full Duplex Modem on WinXP. Is there anybody who likes to share knowledge with me.
|
|
|
|
 |
 | Answering a call julzzz | 2:31 2 Jul '09 |
|
 |
Hi, thanks for ur article. im doing a project on tapi and iam using ur code for that in which i've to answer the calls automatically.but im not able to do that.How can i attend calls automatically? can u help me? plsssssssssss...........
|
|
|
|
 |
 | get incoming phone number via com port? grvijayakumar | 1:39 1 Jul '09 |
|
 |
How to get incoming phone number via com port.
Thanks & Regards
Vijay
|
|
|
|
 |
 | Why I can hear only one (calling) side using TAPI and H.323? GAJERA | 3:01 23 Jun '09 |
|
 |
Hello I am beginner in VOIP.I try to make simple calling and answering application. Here i face this problem, I can hear only one (calling) side using TAPI and H.323.
Please check this following code and Let me know where is my mistake.
//Calling-Ip Calling Function gpAddress->CreateCall(bstr,LINEADDRESSTYPE_IPADDRESS,TAPIMEDIATYPE_AUDIO,&gpCall); hr=SelectTerminalsOnCall(gpCall); hr=gpCall->Connect(0);
/Answer -I add Answer method in event. LRESULT CVOIPCallDlg::OnTAPIEvent(WPARAM wParam, LPARAM lParam) { CString csName; switch(wParam) { case TE_CALLNOTIFICATION: { AddLog("call notification event has occured"); // Get the ITCallNotification interface. IDispatch* pEvent=(IDispatch *)lParam; Answer(pEvent) } break; case TE_CALLSTATE: ITCallStateEvent *a=(ITCallStateEvent *)lParam; ITCallInfo *b; if(a->get_Call(&b) != S_OK) AddLog("get_Call()",hr);
CALL_STATE pCallState;
if(a->get_State(&pCallState)!= S_OK) AddLog("get_State()",hr);
switch(pCallState) { case CS_INPROGRESS: AddLog("dialing"); break; case CS_CONNECTED: AddLog("Connected"); break; case CS_DISCONNECTED: AddLog("Disconnected"); break; case CS_OFFERING: AddLog("A party wants to communicate with you!"); break; case CS_IDLE: AddLog("Call is created!"); break; } break; } pEvent->Release(); return 0; } LRESULT CVOIPCallDlg::Answer(IDispatch* pEvent) { HRESULT hr; ITCallNotificationEvent * pNotify; pEvent->QueryInterface( IID_ITCallNotificationEvent,(void **)&pNotify); ITCallInfo * pCallInfo; pNotify->get_Call(&pCallInfo);
ITBasicCallControl * pBasicCall; hr = pCallInfo->QueryInterface(IID_ITBasicCallControl,(void**)&pBasicCall); hr = pCallInfo->get_Address(&gpAddress); ITStreamControl * pStreamControl; pBasicCall->QueryInterface(IID_ITStreamControl,(void **) &pStreamControl);
IEnumStream * pEnumStreams; ITStream * pStream; hr = pStreamControl->EnumerateStreams(&pEnumStreams); pEnumStreams->Next(1, &pStream, NULL); long lMediaType; TERMINAL_DIRECTION dir; pStream->get_MediaType(&lMediaType); hr = pStream->get_Direction( &dir ); ITTerminal * pTerminal; ITTerminalSupport * pTerminalSupport;
gpAddress->QueryInterface(IID_ITTerminalSupport,(void **)&pTerminalSupport);
hr = pTerminalSupport->GetDefaultStaticTerminal(lMediaType,dir,&pTerminal); hr = pStream->SelectTerminal(pTerminal); hr = pBasicCall->Answer(); return hr; }
Can you help me how it resolve.
Thanks Mahendra
|
|
|
|
 |
|
 |
can you convert your code to C#? i need it. tnx
|
|
|
|
 |
 | TAPI Bhumika07 | 4:33 4 Jun '09 |
|
 |
Hello Sir, I am using your Tapi3_dev application
tell me Hyperterminal setting how do i test that code using hyperterminal i want to get Ring message in hyperterminal text window
tell me what is the use of Line and register button
reply me as early as possible please
|
|
|
|
 |
 | Fails to Register on Windows Vista [modified] asewefy | 22:43 27 May '09 |
|
 |
The Application works fine on windows XP, but it fails to Register the Modem Line On Windows Vista;
Exception: System.ArgumentException: Value does not fall within the expected range.
At: tobj.RegisterCallNotifications(ITAddress pAddress, ... );
Any info ?
Thanks.
modified on Thursday, May 28, 2009 4:28 AM
|
|
|
|
 |
|
 |
http://stackoverflow.com/questions/803015/how-to-get-tapi-to-work-in-vista-with-c[^]
"If you're using C#, using TAPI directly probably won't work. See this KnowledgeBase article for details. Bascially the managed wrapper that Visual Studio creates for the TAPI 3.x COM interface doesn't work. You can use unmanaged code (C++, VB6) to work with TAPI 3.x, or you can use one of the TAPI OCX (a.k.a ActiveX) controls to access TAPI from .Net. Googling for 'TAPI OCX' will get you a page full of free and shareware TAPI controls that you can check out."
|
|
|
|
 |
 | Get incoming phone number Wiebe Tijsma | 5:08 23 May '09 |
|
 |
Hi Devang,
Thank you for your very useful article. Do you have any idea how I can get the phone number of the incoming call?
Thanks,
Wiebe
------------------------------ spoon? what spoon?
http://www.netindustry.nl
|
|
|
|
 |
|
 |
To get the incoming call, first, registered your device using the register button. if you are not getting anything change the media type from audio to datamodem.
Try registertoken(line) = tobj.RegisterCallNotifications(ia(line), True, True, TapiConstants.TAPIMEDIATYPE_DATAMODEM, 2) '''' TAPIMEDIATYPE_AUDIO have been change to TAPIMEDIATYPE_DATAMODEM
MessageBox.Show("Registration token : " & registertoken(line), "Registration Succeed for line " & line) Catch ein As Exception MessageBox.Show("Failed to register on line " & line, "Registration for calls") End Try
Also you will not receive any incoming data from debug. To preview your work properly open your project folder, bin, debug then run the project .exe file this will gice you properly state of your application.
Thanx.
|
|
|
|
 |
|
 |
Thank you for your answer, much appreciated. I've also managed to get it to work using the libraries from http://www.julmar.com/tapi/[^]
------------------------------ spoon? what spoon?
http://www.netindustry.nl
|
|
|
|
 |
 | CALL_STATE.CS_CONNECTED is not executing Member 2535983 | 2:27 3 Apr '09 |
|
 |
Hi First of all thanks for the wonderful code snippet. I am able to make call and getting the response.Also I am getting the responce whet the call getting disconnected But when the user picks up the call the control is not coming to the state CALL_STATE.CS_CONNECTED. Can anyone please let me know how can I get the response at this state.
|
|
|
|
 |
 | [Message Deleted] it.ragester | 6:37 28 Mar '09 |
|
|
 |
 | playing audio file over phone line when call is picked up lisa13 | 2:50 21 Mar '09 |
|
 |
hello i have used your code and connected my mobile as a modem to the computer. the mobile gets detected n i a able to register and make a call also. thnx for the code can you tell me if it is possible to call, n when receiver picks the call a .wav file should be played. plz reply as soon as possible
|
|
|
|
 |
 | My vote of 1 xyz_abc | 4:02 19 Mar '09 |
|
 |
Hello
i use this .net c# code with TAPI3.0 API. but there is problem is that 1. i can't see caller Phone Number. 2. whe i dialing phone number and press call button it Display Error Message 3. i can't answering incomming phone. 4. can't get digit dialing Event 5. when i click disconnect button then after the application become use less until re-start.
i am usern Motorola SM56 fac/modem driver
if can't able to give solution must Delete this artical from code project. not divert anybody's crative mind.
"any one mistake make harmfull for anyone."
from kanthavadiya Amrut
|
|
|
|
 |
 | making second call mostapha amini | 1:38 12 Mar '09 |
|
 |
this program has a problem with modem device in making call if first call disconnect by other end the second call can not be made have any idea?
|
|
|
|
 |
|
 |
Four questions under yours i asked the same thing. Check there for answer
|
|
|
|
 |
 | tapi disconnect problem nimumohd | 21:03 27 Feb '09 |
|
 |
I am using tapii3.0 and its working fine.But the only problem i am facing is that sometimes while disconnecting tapi hangs and i cant do anything,so that i have to restart the system.
microsoft had found a hotfix for this ,but its not working..Anyone plese help me...
|
|
|
|
 |
 | Release call problem... joujoukinder | 2:25 6 Feb '09 |
|
 |
Hello,
When I make a call, I want to disconnect others calls that might be on the line.
I alway get an exception when I try to do it.
Actually, even if I have disconnected a previous call on the line, line.Calls.Count is > 0!!!
ITCollection calls = (ITCollection) line.Calls;
if(calls.Count > 0) { foreach(ITCallInfo item in calls) {
ITBasicCallControl bc = (ITBasicCallControl) item; bc.Disconnect(DISCONNECT_CODE.DC_NORMAL); item.ReleaseUserUserInfo(); } }
Do you know why the line doesn't release the previous calls?
Thanks for helping me!
joujoukinder
|
|
|
|
 |
|
|
Last Updated 15 Jul 2005 |
Advertise |
Privacy |
Terms of Use |
Copyright ©
CodeProject, 1999-2010