3

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.

I'm writing it in C# using TAPI.

What is wrong in that code ?? At button 3 u can see DTMF function.

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)
        {

        }
    }
balazs630
  • 3,421
  • 29
  • 46
Tyrril
  • 31
  • 2
  • Direct use of the TAPI3.dll through COM interop is not supported from .NET. You will run into random problems. Use a 3rd party wrapper. See my answer here: http://stackoverflow.com/a/2334053/44522. It might also be that your TAPI driver doesn't support DTMF. – MicSim Feb 15 '12 at 13:03
  • Thanks for quick respon, du u have some samples of that C++ code ? – Tyrril Feb 16 '12 at 11:58
  • No, I'm sorry, but I think there are some samples included in the download package itself. – MicSim Feb 16 '12 at 12:27

1 Answers1

0

You can use ATAPI library for .Net TAPI library. It also has some example included so that you can understand how TAPI works. ATAPI is hosted in CodePlex and is MIT licensed. Search google for ATAPI codeplex to get the library.

fadedreamz
  • 1,156
  • 1
  • 10
  • 19