1

I developed a softphone for windows, I know how to register it as default tell application by reading this question, but I don`t know how get arguments sent from a web application or another win application while my softphone is running.

The standard code to call tell app from web app is something like this:

window.open("tel: 05525825");
Cœur
  • 37,241
  • 25
  • 195
  • 267
Babak Fakhriloo
  • 2,076
  • 4
  • 44
  • 80

2 Answers2

1

If you have registered your application for the scheme tel: and the Command is "yourapp.exe %1", then you can read them from the commandline arguments as explained in How to access command line parameters outside of Main in C#:

string arguments = Environment.GetCommandLineArgs();
string phoneNumber = arguments[1];

Of course you need to do some sanity checking before bluntly accessing and using the array element.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Thanks @codecas, I would check it out. But is there a listener or event handler for this to read Environment.GetCommandLineArgs();? – Babak Fakhriloo Mar 25 '15 at 13:41
0

If you setup the protocol URL keys correctly your application will be run with the data in the command line (E.g. args[] in main())

To pass data to an already running instance of your application the easiest way is to use the StartupNextInstance event provided by VisualBasic.ApplicationServices and re-process new incomming command lines:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;

namespace Foo
{
    static class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            var applicationBase = new ThisWindowsApplicationBase();
            applicationBase.StartupNextInstance += (sender, e) => { applicationBase.HandleCommandLine(e.CommandLine); };
            applicationBase.Run(args);
        }
    }

    class ThisWindowsApplicationBase : WindowsFormsApplicationBase
    {
        internal ThisWindowsApplicationBase()
            : base()
        {
            this.IsSingleInstance = true;
            this.MainForm = new Form1();

            this.HandleCommandLine(Environment.GetCommandLineArgs().Skip(1));
        }

        internal void HandleCommandLine(IEnumerable<string> commandLine)
        {
            this.MainForm.Text = "Processing: " + commandLine.FirstOrDefault();
        }
    }
}

Note this will not fire for the first run.

Alex K.
  • 171,639
  • 30
  • 264
  • 288