-
Sep 14th, 2024, 11:24 AM
#41
Re: Any issue with DDE?
Originally Posted by Elroy
Hi Eduardo,
If it were me looking at DDE, the first thing I'd do is get clear on what I'm actually trying to do (and why I'd consider DDE). And I'd post a question about "that task", and elicit ideas on the best way to accomplish that.
OK, I will reformulate the question:
I wanted a method of handling previous instances of the program (to activate it) that was as easy as possible, better if not requiring APIs.
I thought of using DDE. And tried it and it worked (it was just an unimportant little utility program that I've made, I didn't want to spend much time in doing it).
Now I was about to post my example in the Codebank but thought "Why nobody uses DDE? I'll ask first".
And here we are.
Clearer now?
I'm not asking how to do that, I know many ways of handling a previous instance (the first one would be SetProp (GetDesktopWindow, Value) --- GetProp (GetDesktopWindow, Value) --- If IsWindow (Value) Then...
Originally Posted by Elroy
Regarding inter-process communications, I'd probably employ other approaches, but primarily because I'm more familiar with them, have used them, and trust them.
Yes, the point is trust. We don't use DDE so we don't know it, and then we don't trust it because we are not familiar with. That's also the reason of my question.
Edit: Additional note: for larger programs I have all that functionality in a component, but this one wanted it to be a single exe without dependencies.
Now I'm thinking that this approach does the same and much easier.
Last edited by Eduardo-; Sep 14th, 2024 at 11:33 AM.
-
Sep 14th, 2024, 12:50 PM
#42
Re: Any issue with DDE?
Originally Posted by Eduardo-
...
I wanted a method of handling previous instances of the program (to activate it) that was as easy as possible...
Yes, that sounds almost exactly like the reason I once explored it. And, if I'm not mistaken, it can be used to use a single instance of a program to "asynchronously" open several files ... and do it without every loading a second instance of the program. <--- It's that last part that's actually interesting.
I searched for "registry" in this thread, and didn't find it. And, it's my understanding that it takes some specific registry entries to actually accomplish this. I'll explore a bit and see if I can find out more about this.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Sep 14th, 2024, 01:03 PM
#43
Re: Any issue with DDE?
Hmmm, I asked Gemini, and it gave me all kinds of information (after a few queries).
But, it concluded with this:
In conclusion, while DDE can be used to implement a single-instance application, it's generally recommended to consider more modern approaches like using a mutex or inter-process communication mechanisms provided by newer technologies. These methods often offer better performance, reliability, and flexibility.
IDK, after that comment, I might take a different approach.
Specifically, I might write a "stub" program that's used to get everything started. Then, it shells to the "actual" program, looking for an already running instance, and handling that appropriately ... passing whatever file to be opened to where I wanted. I can even see situations where I might want to prompt whether I want my file opened in an existing program instance or opened in a new instance. I actually do precisely that with PSP, possibly getting four or five "related" images opened in one instance, and then getting another PSP instance opened for another unrelated image. Not sure DDE would give you that flexibility.
Again IDK, but I do remember DDE being touchy and difficult to work with. But maybe I didn't take enough time to learn its idiosyncrasies.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
-
Sep 14th, 2024, 01:49 PM
#44
Re: Any issue with DDE?
Originally Posted by Elroy
Yes, that sounds almost exactly like the reason I once explored it. And, if I'm not mistaken, it can be used to use a single instance of a program to "asynchronously" open several files ... and do it without every loading a second instance of the program. <--- It's that last part that's actually interesting.
I searched for "registry" in this thread, and didn't find it. And, it's my understanding that it takes some specific registry entries to actually accomplish this. I'll explore a bit and see if I can find out more about this.
I didn't read anything about that.
What I can say is that for executing your program by shelling a file with a custom file extension you need to associate that extension with your exe (of course you already know that, and that is where the registry is involved, but for testing you can do it manually in Windows), and then when the program launches this instance, if there is another instance already running you can send the Command$ containing the path of the file to be opened to the existing instance with DDE.
And here is my example updated to do that:DDE Sample ActivatePrevinstance and pass parameter.zip
-
Sep 14th, 2024, 01:53 PM
#45
Re: Any issue with DDE?
Originally Posted by Elroy
Hmmm, I asked Gemini, and it gave me all kinds of information (after a few queries).
But, it concluded with this:
IDK, after that comment, I might take a different approach.
Specifically, I might write a "stub" program that's used to get everything started. Then, it shells to the "actual" program, looking for an already running instance, and handling that appropriately ... passing whatever file to be opened to where I wanted. I can even see situations where I might want to prompt whether I want my file opened in an existing program instance or opened in a new instance. I actually do precisely that with PSP, possibly getting four or five "related" images opened in one instance, and then getting another PSP instance opened for another unrelated image. Not sure DDE would give you that flexibility.
Again IDK, but I do remember DDE being touchy and difficult to work with. But maybe I didn't take enough time to learn its idiosyncrasies.
The AI chatbots are totally prejudiced with the same prejudices that people have and wrote on internet.
You need to do with it the same I did here: ask specifically what are the problems, to see if it can tell something real.
-
Sep 14th, 2024, 02:15 PM
#46
Re: Any issue with DDE?
If you don't want to use DDE, you can use VanGoghGames approach, it you be a good use case for that.
PS: and I don't think that ChatBots will be able to criticize it
-
Sep 14th, 2024, 03:54 PM
#47
Re: Any issue with DDE?
so I made the code as small possible
Code:
Private Sub Form_Load()
Dim arrForm(0) As Main, pSA&
GetMem4 ByVal ArrPtr(arrForm), pSA
pSA = pSA - 16
If GetActiveObject(pSA) = 0 Then
MsgBox "Already Running.", vbExclamation
Unload Main
Else
RegisterActiveObject Main, pSA
MainGameProcedure
End If
End Sub
and it works.
I noticed that if I run the .exe and I run the IDE, both will start. so the exe and IDE is not the same.
using mutex it will not. but its not a big deal since its just me that can run it like that.
-
Sep 14th, 2024, 04:24 PM
#48
Fanatic Member
Last edited by qvb6; Sep 14th, 2024 at 05:03 PM.
-
Sep 14th, 2024, 05:17 PM
#49
Re: Any issue with DDE?
Originally Posted by baka
so the exe and IDE is not the same.
If you run the EXE from the IDE (using Shell or ShellExecuteW) then they will be treated the same!
Also why don't you put that code in "Sub Main" instead of "Form_Load"? That way it won't load any forms if the app is already started.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|