I am using tapi programming in order to communicate with a device and send-receive calls. At this moment i am able to make external calls, and "see" who is calling me when i pick up the phone. For some reason i can't see the number at the event < CALL_STATE.CS_OFFERING > (When your phone rings). I post my code below (it is similar to one i found on the internet). Any help will be appreciated!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TapiSample
{
public partial class Form1 : Form
{
static public IAsyncResult result;
public Form1()
{
InitializeComponent();
tapi = new TAPI3Lib.TAPIClass();
tapi.Initialize();
foreach (TAPI3Lib.ITAddress ad in (tapi.Addresses as TAPI3Lib.ITCollection))
{
cbLines.Items.Add(ad.AddressName);
}
tapi.EventFilter = (int)(TAPI3Lib.TAPI_EVENT.TE_CALLNOTIFICATION |
TAPI3Lib.TAPI_EVENT.TE_CALLINFOCHANGE |
TAPI3Lib.TAPI_EVENT.TE_DIGITEVENT |
TAPI3Lib.TAPI_EVENT.TE_PHONEEVENT |
TAPI3Lib.TAPI_EVENT.TE_CALLSTATE |
TAPI3Lib.TAPI_EVENT.TE_GENERATEEVENT |
TAPI3Lib.TAPI_EVENT.TE_GATHERDIGITS |
TAPI3Lib.TAPI_EVENT.TE_REQUEST);
tapi.ITTAPIEventNotification_Event_Event += new TAPI3Lib.ITTAPIEventNotification_EventEventHandler(tapi_ITTAPIEventNotification_Event_Event);
}
TAPI3Lib.TAPIClass tapi = null;
TAPI3Lib.ITAddress line = null;
int cn = 0;
private void button1_Click(object sender, EventArgs e)
{
if (line != null)
{
line = null;
if (cn != 0) tapi.UnregisterNotifications(cn);
}
foreach (TAPI3Lib.ITAddress ad in (tapi.Addresses as TAPI3Lib.ITCollection))
{
if (ad.AddressName == cbLines.Text)
{
line = ad;
break;
}
}
if (line != null)
{
cn = tapi.RegisterCallNotifications(line, true, true, TAPI3Lib.TapiConstants.TAPIMEDIATYPE_AUDIO, 2);
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (cn != 0) tapi.UnregisterNotifications(cn);
}
delegate void AddLogDelegate(string text);
private void AddLog(string text)
{
if (this.InvokeRequired)
{
result = this.BeginInvoke(new AddLogDelegate(AddLog), new object[] { text });
}
listBox1.Items.Insert(0, text);
}
private void tapi_ITTAPIEventNotification_Event_Event(TAPI3Lib.TAPI_EVENT TapiEvent, object pEvent)
{
try
{
switch (TapiEvent)
{
case TAPI3Lib.TAPI_EVENT.TE_CALLNOTIFICATION:
AddLog("call notification event has occured");
break;
case TAPI3Lib.TAPI_EVENT.TE_CALLSTATE:
TAPI3Lib.ITCallStateEvent tcallStateEvent = (TAPI3Lib.ITCallStateEvent)pEvent;
TAPI3Lib.ITCallInfo b = tcallStateEvent.Call;
switch (b.CallState)
{
case TAPI3Lib.CALL_STATE.CS_OFFERING:
string str2 = b.get_CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLERIDNUMBER);
AddLog("Number Calling:" + str2); //Doesn't work
return;
case TAPI3Lib.CALL_STATE.CS_CONNECTED:
string str = b.get_CallInfoString(TAPI3Lib.CALLINFO_STRING.CIS_CALLERIDNUMBER);
AddLog("Communicating with: " + str);
return;
case TAPI3Lib.CALL_STATE.CS_DISCONNECTED:
this.EndInvoke(result);
AddLog("Call Disconnected");
return;
}
break;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
if (line == null) return;
TAPI3Lib.ITBasicCallControl bc = line.CreateCall(teNumber.Text, TAPI3Lib.TapiConstants.LINEADDRESSTYPE_PHONENUMBER, TAPI3Lib.TapiConstants.TAPIMEDIATYPE_AUDIO);
bc.Connect(false);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}