Opening file associations on Windows

Hi all,

My setup program makes the file association successfully, and I’ve implemented the Application.OpenDocument event.

Everything works correctly when my application is closed and the user double-clicks one of the associated files from File Explorer. My app launches and opens the file.

The issue arises when my app is already running. Instead of the current instance opening the double-clicked file, it launches a new instance, which fails to run due to my Mutex / Prevent Multiple Instances code.

What’s the correct approach to ensure that the associated file opens in the existing instance of the app?

This is expected behavior on Windows. If you really need it to go to the main instance you can IPCSocket to your main instance to tell it what to do. I’m a bit foggy on the details, but this was how the feedback application worked back in the day.

Greg might be able to say more.

This thread has an example: Detect if application is already open - #16 by Thom_McGrath

Thanks everyone,

IPCSockets seem like the way to go.

There’s a logical issue I’m missing though. My mutex checking happens in App.Opening, but this prevents the OpenDocument event on the second instance from running. Where are you “supposed” to check for a second instance if not App.Opening?

Edit: I should also mention this is all exceptionally difficult to debug, is there a way to simulate a file association being double-clicked in the IDE?

Ahhhh I forgot that the file to open is passed as a command line parameter. Got the logic issue sorted.

Still wish there was an easier way to debug this though, especially with multiple instances and IPCSockets.

1 Like