locked
hangup phone call RRS feed

  • Question

  • hi all.

     

    how can I do for hangup any current phone call from my application?

     

    I must to restrict some outgoing call since my application, I already launch a method when a new call is done, but if the call number is in the list I need to hang it up.

     

    I had test all I thought can help me but nothing work.

     

    I used Tapi linedrop function, but don't work, i read somewhere is because the application must be the owner of the call. is there any way

     

    thanks for any help.

    Wednesday, April 25, 2007 6:44 PM

Answers

  • You'd need to use TAPI to hang up a call

    Here is a C++ sample how to do this (unfortunatly I don't have a C# or VB.NET version)

     

    Code Snippet

    void HangupCall ()
    {
     DWORD dwNumDevs;
     DWORD dwAPIVersion = TAPI_API_HIGH_VERSION;
     LINEINITIALIZEEXPARAMS liep;
     HLINEAPP hLineApp = 0;
     HLINE hLine = 0;
     DWORD dwTAPILineDeviceID;
     const DWORD dwMediaMode = LINEMEDIAMODE_DATAMODEM | LINEMEDIAMODE_INTERACTIVEVOICE;
     DWORD dwExtVersion;

     LONG result = 0;

     liep.dwTotalSize = sizeof (liep);
     liep.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;

     if (lineInitializeEx (&hLineApp, 0, 0, L"my Sample", &dwNumDevs, &dwAPIVersion, &liep) == 0)
     {
      dwTAPILineDeviceID = GetTSPLineDeviceID (hLineApp, dwNumDevs, TAPI_API_LOW_VERSION, TAPI_API_HIGH_VERSION, CELLTSP_LINENAME_STRING);

      result = lineOpen (hLineApp, dwTAPILineDeviceID, &hLine, dwAPIVersion, 0, 0, LINECALLPRIVILEGE_OWNER, dwMediaMode, 0);
      if (result == 0)
      {
       result = lineNegotiateExtVersion (hLineApp, dwTAPILineDeviceID, dwAPIVersion,
        EXT_API_LOW_VERSION, EXT_API_HIGH_VERSION, &dwExtVersion);


       LPLINECALLLIST lpCallList;
       lpCallList = (LPLINECALLLIST)::malloc(512);

       lpCallList->dwTotalSize = 512;

       result = lineGetNewCalls (hLine, NULL, LINECALLSELECT_LINE, lpCallList);

       if (result == 0)
       {
        for (DWORD i = 0; i < lpCallList->dwCallsNumEntries; i++)
        {
         BYTE* p  = (BYTE*)(lpCallList) + lpCallList->dwCallsOffset + i * sizeof (HCALL);
         HCALL hCallToDrop = *(HCALL*)p;

         result = lineSetCallPrivilege (hCallToDrop, LINECALLPRIVILEGE_OWNER );
         result = lineDrop (hCallToDrop, NULL, 0);
        }
       }

       ::lineClose (hLine);
      }
     

      lineShutdown(hLineApp);
     }
    }

    DWORD GetTSPLineDeviceID(const HLINEAPP hLineApp,
                             const DWORD dwNumberDevices,
                             const DWORD dwAPIVersionLow,
                             const DWORD dwAPIVersionHigh,
                             const TCHAR* const psTSPLineName)
    {
        DWORD dwReturn = 0xffffffff;
        for(DWORD dwCurrentDevID = 0 ; dwCurrentDevID < dwNumberDevices ; dwCurrentDevID++)
        {
            DWORD dwAPIVersion;
            LINEEXTENSIONID LineExtensionID;
            if(0 == lineNegotiateAPIVersion(hLineApp, dwCurrentDevID,
                                            dwAPIVersionLow, dwAPIVersionHigh,
                                            &dwAPIVersion, &LineExtensionID))
            {
                LINEDEVCAPS LineDevCaps;
                LineDevCaps.dwTotalSize = sizeof(LineDevCaps);
                if(0 == lineGetDevCaps(hLineApp, dwCurrentDevID,
                                       dwAPIVersion, 0, &LineDevCaps))
                {
                    BYTE* pLineDevCapsBytes = new BYTE[LineDevCaps.dwNeededSize];
                    if(0 != pLineDevCapsBytes)
                    {
                        LINEDEVCAPS* pLineDevCaps = (LINEDEVCAPS*)pLineDevCapsBytes;
                        pLineDevCaps->dwTotalSize = LineDevCaps.dwNeededSize;
                        if(0 == lineGetDevCaps(hLineApp, dwCurrentDevID,
                                               dwAPIVersion, 0, pLineDevCaps))
                        {
                            if(0 == _tcscmp((TCHAR*)((BYTE*)pLineDevCaps+pLineDevCaps->dwLineNameOffset),
                                            psTSPLineName))
                            {
                                dwReturn = dwCurrentDevID;
                            }
                        }
                        delete[]  pLineDevCapsBytes;
                    }
                }
            }
        }
        return dwReturn;
    }

     

    This sample shows the APIs you need to call in your managed implementation. The biggest challange is to do the P/Invoke stuff.

     

    If your willing to buy a third party component - go for the OpenNETCF.com does have managed telephony component (

    http://www.opennetcf.com/CompactFramework/Products/TelephonyLibrary/tabid/134/Default.aspx). This componet should provide all you need in managed code.

     

    Hope this helps

    Michael

     

    Wednesday, May 2, 2007 11:21 PM

All replies

  • remove / disable the phone app on the device.

     

    initiate the call via TAPI from your application using the allowable numbers to select from.

     

     

     

    Thursday, April 26, 2007 12:35 PM
  • thanks for your answer, but I can't remove or disable the app on device, I can not interfere with the normal working of the device. 

     

    the client can call any number but if the dialed number is in the list I must to stop it and start another call to another fixed number.

     

    taht I need is to stop the outgoing call or redirect it to another number.

     

    thanks for your help.

    Friday, April 27, 2007 3:38 PM
  • You could make an application that mimics the built in phone application.

     

    This may also assist you.

    http://www.devx.com/wireless/Article/32305/1954?pf=true

     

    Friday, April 27, 2007 6:07 PM
  • thanks again for answer.

     

    I already have an application tha uses the state api ibn C#. this is my piece of code that use it.

     

     

    SystemState _phoneCallContactState;

    public Form1()

    {

    InitializeComponent();

    Settings.startSettings();

    Settings.LoadSettingsFromFile();  //fill the list with the numbers will be redirected

     

    _phoneCallContactState = new SystemState(SystemProperty.PhoneCallCalling);

    _phoneCallContactState.Changed += new ChangeEventHandler(_phoneCallContactState_Changed); //add handler

    }

     

     

     

    void _phoneCallContactState_Changed(object sender, ChangeEventArgs args) //method  launched when a call is done

    {

       if ((int)(SystemState.GetValue(SystemProperty.PhoneCallCalling)) == 1)

       {

        Phone telefono = new Phone();

       string callerNumber = (string)SystemState.GetValue(SystemProperty.PhoneTalkingCallerNumber);

        if (callerNumber != null)

             {

             string newNumber = Settings.isRegisteredNumber(callerNumber.Trim());  //if is in the list get number to redirect

              if (newNumber != null)

                 {

                 hangUpCall();   // this is the missing function

                     for (int i = 0; i < 10; i++){

                          if ((int)(SystemState.GetValue(SystemProperty.PhoneCallCalling)) == 1){  //wait for the call be hangup

                               Thread.Sleep(2000);

                     }

                     else

                     break;

                 }

              telefono.Talk(newNumber);  //make the definitive call

              }

           }

       }

    }

     

    the application makes the new call when I hung up the call manually pressing the end call button or when the call is ended.

     

    the piece of code I need is that one for hangup the call.

     

    thanks again for your help

    Friday, April 27, 2007 7:14 PM
  • You'd need to use TAPI to hang up a call

    Here is a C++ sample how to do this (unfortunatly I don't have a C# or VB.NET version)

     

    Code Snippet

    void HangupCall ()
    {
     DWORD dwNumDevs;
     DWORD dwAPIVersion = TAPI_API_HIGH_VERSION;
     LINEINITIALIZEEXPARAMS liep;
     HLINEAPP hLineApp = 0;
     HLINE hLine = 0;
     DWORD dwTAPILineDeviceID;
     const DWORD dwMediaMode = LINEMEDIAMODE_DATAMODEM | LINEMEDIAMODE_INTERACTIVEVOICE;
     DWORD dwExtVersion;

     LONG result = 0;

     liep.dwTotalSize = sizeof (liep);
     liep.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;

     if (lineInitializeEx (&hLineApp, 0, 0, L"my Sample", &dwNumDevs, &dwAPIVersion, &liep) == 0)
     {
      dwTAPILineDeviceID = GetTSPLineDeviceID (hLineApp, dwNumDevs, TAPI_API_LOW_VERSION, TAPI_API_HIGH_VERSION, CELLTSP_LINENAME_STRING);

      result = lineOpen (hLineApp, dwTAPILineDeviceID, &hLine, dwAPIVersion, 0, 0, LINECALLPRIVILEGE_OWNER, dwMediaMode, 0);
      if (result == 0)
      {
       result = lineNegotiateExtVersion (hLineApp, dwTAPILineDeviceID, dwAPIVersion,
        EXT_API_LOW_VERSION, EXT_API_HIGH_VERSION, &dwExtVersion);


       LPLINECALLLIST lpCallList;
       lpCallList = (LPLINECALLLIST)::malloc(512);

       lpCallList->dwTotalSize = 512;

       result = lineGetNewCalls (hLine, NULL, LINECALLSELECT_LINE, lpCallList);

       if (result == 0)
       {
        for (DWORD i = 0; i < lpCallList->dwCallsNumEntries; i++)
        {
         BYTE* p  = (BYTE*)(lpCallList) + lpCallList->dwCallsOffset + i * sizeof (HCALL);
         HCALL hCallToDrop = *(HCALL*)p;

         result = lineSetCallPrivilege (hCallToDrop, LINECALLPRIVILEGE_OWNER );
         result = lineDrop (hCallToDrop, NULL, 0);
        }
       }

       ::lineClose (hLine);
      }
     

      lineShutdown(hLineApp);
     }
    }

    DWORD GetTSPLineDeviceID(const HLINEAPP hLineApp,
                             const DWORD dwNumberDevices,
                             const DWORD dwAPIVersionLow,
                             const DWORD dwAPIVersionHigh,
                             const TCHAR* const psTSPLineName)
    {
        DWORD dwReturn = 0xffffffff;
        for(DWORD dwCurrentDevID = 0 ; dwCurrentDevID < dwNumberDevices ; dwCurrentDevID++)
        {
            DWORD dwAPIVersion;
            LINEEXTENSIONID LineExtensionID;
            if(0 == lineNegotiateAPIVersion(hLineApp, dwCurrentDevID,
                                            dwAPIVersionLow, dwAPIVersionHigh,
                                            &dwAPIVersion, &LineExtensionID))
            {
                LINEDEVCAPS LineDevCaps;
                LineDevCaps.dwTotalSize = sizeof(LineDevCaps);
                if(0 == lineGetDevCaps(hLineApp, dwCurrentDevID,
                                       dwAPIVersion, 0, &LineDevCaps))
                {
                    BYTE* pLineDevCapsBytes = new BYTE[LineDevCaps.dwNeededSize];
                    if(0 != pLineDevCapsBytes)
                    {
                        LINEDEVCAPS* pLineDevCaps = (LINEDEVCAPS*)pLineDevCapsBytes;
                        pLineDevCaps->dwTotalSize = LineDevCaps.dwNeededSize;
                        if(0 == lineGetDevCaps(hLineApp, dwCurrentDevID,
                                               dwAPIVersion, 0, pLineDevCaps))
                        {
                            if(0 == _tcscmp((TCHAR*)((BYTE*)pLineDevCaps+pLineDevCaps->dwLineNameOffset),
                                            psTSPLineName))
                            {
                                dwReturn = dwCurrentDevID;
                            }
                        }
                        delete[]  pLineDevCapsBytes;
                    }
                }
            }
        }
        return dwReturn;
    }

     

    This sample shows the APIs you need to call in your managed implementation. The biggest challange is to do the P/Invoke stuff.

     

    If your willing to buy a third party component - go for the OpenNETCF.com does have managed telephony component (

    http://www.opennetcf.com/CompactFramework/Products/TelephonyLibrary/tabid/134/Default.aspx). This componet should provide all you need in managed code.

     

    Hope this helps

    Michael

     

    Wednesday, May 2, 2007 11:21 PM
  •  

    Thanks a lot Michael.

     

    I test the code and it appear to work fine in device.  I must test in other devices.

     

    I had test with c++, but i couldn't make it work, I see in my code that I was not using the lineSetCallPrivilege method, and because that it couldn't hangup the call.

     

    thanks again.

    Thursday, May 3, 2007 12:39 AM
  • emulator key press 

     

    ------------------dropcall.cs--------------------------------------

    using System;
    //using System.Linq;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;

    namespace dropcallDemo
    {
        public static class DropCall
        {
            #region private field
            //End键的VK键值 F4
            private const int VK_F4 = 0x73;
            private const int KEYEVENTF_KEYUP = 0x0002;
            #endregion

            #region public fiield
            //封禁的电话号码单
            public static List<String> BannedList = new List<String>();

            /// <summary>
            /// 模拟一次按键操作
            /// </summary>
            public static void Drop()
            {
                MyRef.keybd_event(VK_F4, 0, 0, 0);
                MyRef.keybd_event(VK_F4, 0, KEYEVENTF_KEYUP, 0);
            }
            #endregion
        }

        #region Invoke Class
        public static class MyRef
        {
            //keybd_event API用于想系统发送按键消息
            [DllImport("coredll.dll")]
            public static extern void keybd_event(
                byte bVk,
                byte bScan,
                int dwFlags,
            int dwExtraInfo);
        }
        #endregion
    }

    then you can use it like this

     

      DropCall.Drop();

    Thursday, May 8, 2008 3:08 PM