[quote=423421:@Tim Streater]Hmmm. OK, thanks for that warning. A second instance of my app would start messing with the databases used by the first. It will require some re-arrangement to avoid that.
Edit: or, more likely, a helper command-line app. Food for thought.[/quote]
Here’s a ripped-out slightly modified for ease-of-use version of code from one of our payment services…
For a Mutex, you can add a property mMutex to your App as type Mutex
and in the App.Open Event try something like
[code]mMutex = New Mutex(“MyAppMutex”)
If Not mMutex.TryEnter Then
'We only need one copy running to access the built-in payment server…
//If you need to snatch any commands off the command line you can use the following line…
Dim cmdline as String = System.CommandLine
///set some flags to not interact with the database… and pass info to wherever it needs to be…
Dim httpnew as new HTTPSocket
httpnew.Yield = true
Dim y as String = httpnew.Get("http://127.0.0.1:7777/?" +EncodeURLComponent(cmdline),15)
//Above we pass one-click payment data to the main application from the website or wherever the URI was clicked…the first instance is listening for the request…
mMutex = Nil
//Quit the second copy if needed.
Quit
End If[/code]
To test this on windows… add a socket to listen for incoming information
And to create the URI… here’s a re-usable method for Windows…
[code]Public Sub RegisterURI(URI as String, Name as String)
#if TargetWindows then
Dim reg As RegistryItem
Try
reg = new RegistryItem("HKEY_CLASSES_ROOT\" + URI, False) 'RegistryItem("HKEY_LOCAL_MACHINE\\SOFTWARE\\ORACLE\", FALSE)
Catch e as RegistryAccessErrorException
reg = new RegistryItem("HKEY_CLASSES_ROOT")
reg = reg.AddFolder(URI)
reg.DefaultValue = "URL:" + Name
reg.Value("URL Protocol") = ""
Dim defaultIcon As RegistryItem = reg.AddFolder("DefaultIcon")
defaultIcon.DefaultValue = """" + App.ExecutableFile.NativePath + """,1"
Dim commandItem As RegistryItem = reg.AddFolder("shell").AddFolder("open").AddFolder("command")
commandItem.DefaultValue = """" + App.ExecutableFile.NativePath + """ ""%1"""
Catch f as RegistryAccessErrorException
exit
End
#Endif
End Sub[/code]
For Mac, to do the above, you will need to modify the application plist.
I rarely see anyone inquire about Linux, but for full cross-platform Custom URI handline, you will need to manually, or use a shell, to do the following
http://archive.is/8C3zb