How to make a call with OpenNetCf TAPI (Windows Mobile)

How to make a call with OpenNetCf TAPI (Windows Mobile C#)
G.Morreale

Introduction

The simplest way to make a call in windows mobile is by using the following

http://msdn.microsoft.com/en-us/library/microsoft.windowsmobile.telephony.phone.talk.aspx

 

that is the WindowsMobile Managed Telephony api.


Microsoft.WindowsMobile.Telephony.Phone myPhone = new Microsoft.WindowsMobile.Telephony.Phone();

myPhone.Talk("0123456789", true);


In this simple way the default phone manager appear and the call is managed by it.

Tapi

If you want a more flexible way to manage the phone module in your windows mobile device you have to use the TAPI
The TAPI is an application interface for telephony application, and microsoft make available it also for windows mobile(http://msdn.microsoft.com/en-us/library/aa455190.aspx).


Tapi Wrapper

Ok, now if you want to simplify the interaction with the unmanaged tapi library, you must use a wrapper.
A nice wrapper that I can find is an OpenNetCf Wrapper.
You can download it and various example from http://tapi.codeplex.com/

The example

Make a new smart device project, and add OpenNETCF.Telephony.dll in the references.

You can build the source code and obtaion the dll by the zip downloaded or find it in extracting TelephonySamples.zip file(makeCall ->  bin -> Debug -> OpenNETCF.Telephony.dll)รน

Now, we insert the tapi init code in the load event of the Form1.

using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OpenNETCF.Telephony;

namespace MakeCall2
{
    public partial class Form1 : Form
    {

        private Telephony tapi;
        private Line line;
       
        public Form1()
        {
            InitializeComponent();
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {
            // Open Tapi
            tapi = new Telephony();
            tapi.Initialize();      
            // Get the phone line in the specified media mode and with or not call privilege
           line = tapi.CellularLine(MediaMode.InteractiveVoice, CallPrivilege.None);
        }
    }
}
So now, add a textbox to the form for telephone number input and a button in order to permits the call.
In the click event of the call you have to add the following:

        private void btMakeCall_Click(object sender, EventArgs e)
        {
            //the tbNumber is the textbox, and 39 is the country code of the called number, the third 
            //parameter is for suppressing or not the caller id
            line.MakeCall(tbNumber.Text, 39, false);
        }

remember to shutdown the tapi instance.

     private void Form1_Closing(object sender, CancelEventArgs e)
        {
            tapi.Shutdown();
        }

Possible Issues

When using tapi.CellularLine method the line returned can be null inspite the line exist and is activable.
I debug the OpenNETCF.Telephony and the problem is on 
"if (dc.ProviderName == NativeMethods.CELLTSP_PROVIDERINFO_STRING)"

When using the .net compact framework 3.5 the dc.ProviderName string is suffixed with a different char.
Now I don't know the cause of this, but we can avoid this problem by using this matching:
"if (dc.ProviderName.contains(NativeMethods.CELLTSP_PROVIDERINFO_STRING))"







No comments: