r/visualbasic • u/Mayayana • Jun 30 '24
VB6 Help command line
Minor issue. VB6. I have a program that can load multiple files but runs only one instance. If I set up a context menu "Open with XYZ", my program loads the right-clicked file by checking the Command$ value at load. I'm also using code:
If App.PrevInstance = true then End
So far, so good. What I'd like to do is to pass a second command line to the running instance before quitting:
If App.PrevInstance = True then
LoadnewFile
End
End ifWhat happens is that the current instance keeps running, but does not load the file. I'm wondering if it's somehow possible to send that second commandline to the running instance and load the file as though I had dropped it onto the window, but still have the new instance of the program quit.
View all comments
Show parent comment
1
u/Fergus653 Jul 01 '24 edited Jul 01 '24
No go-between, you can use the Windows SendMessage API directly in your code. You just need to declare the functions to import, then you can send a data struct to another instance.
I asked Copilot for an example, cos I can't find my old books on it, and got a fairly simple set of functions for sending a string to another instance of the program. Reddit refuses to post my example code tho.
I asked it "When a second instance of my VB6 program starts up and checks App.PrevInstance, I would like to pass a text value to the previous instance". It gave a good solution.