4

I want to trigger an event in my running application and deliver arguments with the call of a URL scheme in Windows 10. I made the following registry entry:

HKEY_CLASSES_ROOT
alert
    (Default) = "URL:Alert Protocol"
    URL Protocol = ""
    DefaultIcon
        (Default) = "alert.exe,1"
    shell
        open
            command
                (Default) = "C:\Program Files\Alert\alert.exe" "%1"

Obviously, this always starts a new instance of my application with an argument, when calling 'alert:arg1'. But I want Windows to call my already running instance.

With Mac, the call of this URL scheme triggers an event, I can catch. Exactly, as I want. To do this, I added the following part to alert.app/Contents/Info.plist:

<array>
  <dict>
    <key>CFBundleURLName</key>
    <string>Alert</string>
    <key>CFBundleURLSchemes</key>
    <array>
            <string>alert</string>
    </array>
  </dict>
</array>

So how do I realise this on Windows? I'm programming this application in XOJO with object-oriented BASIC, but I'll be happy about a general solution.

Robert Beier
  • 81
  • 2
  • 9
  • 2
    Windows simply relaunches the executable so your question is really "how to do IPC on Windows". I don't know what you stack supports but this is generally accomplished by having the exe try to create a named mutex when it loads, if it can't it knows another instance of itself is running at which point it uses an IPC mechanism so forward its command line, by sending over a named pipe for example. – Alex K. Jul 28 '17 at 12:13
  • 1
    Make your application single-instance (the de facto way is using a Mutex) and send a message from the newly started instance to the already-running one, then exit. – CodeCaster Jul 28 '17 at 12:25
  • Thanks to Alex and CodeCaster for leading me the right way. With this information I found a good article with working code and posted it as an answer. – Robert Beier Jul 28 '17 at 12:36

1 Answers1

3

Well, after reading the answer of Alex, I searched how to realise this with code and found a well explained and working solution from Brad Smith written in C#.

The registry entry above can stay as it is, but the program also needs:

  • A service class (which is exposed by the application instance
    via .NET remoting)
  • A modified entry point (which will either communicate with the service and then terminate, or start the application normally)

Read his article and look at his code for further explanation.

Robert Beier
  • 81
  • 2
  • 9