Author Topic: File association to registry fails?  (Read 19927 times)

grv575

  • Guest
Re: File association to registry fails?
« Reply #15 on: January 04, 2006, 12:04:36 pm »
I can manually start several Firefox'es by clicking on the program icon of firefox. So it's not that only one instance can exist. Wonder how they do that ?
I don't know what firefox uses, but creating a named mutex is another common technique to allow only one running instance.

Yeah the common idiom is to use a named mutex and if it is already acquired then use IPC to pass over the commandline args to the existing instance and then exit.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #16 on: January 04, 2006, 12:06:12 pm »
that might be possible, yes, since you can query windows for the existing windows. And maybe they hand it over to the other one then.
[EDIT] It's like that, I checked the task manager, shortly there's an extra instance and then it is gone.

And if you have 2 firefoxes open, it will open it in the one that was last active.

So : options :
 1) should we add such thing to CB also : query if others already runing and pass it over then (maybe even use selectable : start new instance (but then ths user should already have allowed multiple instance setting) or open in existing instance
 2) Fix the DDE to get rid of the error messages

Drop the feedback ... ;-)


 

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: File association to registry fails?
« Reply #17 on: January 04, 2006, 12:34:02 pm »
I don't know what firefox uses, but creating a named mutex is another common technique to allow only one running instance.
This is exactly what Code::Blocks does (wxSingleInstanceChecker does just that).
But: this does not solve the problem, it really makes it worse, it leads to the "another instance is already running, quitting now" issue.

The problem with multiple instances is that we need a bulletproof way to hand the commandline from a new instance to the already running instance. Unluckily, this is not precisely trivial to implement cross-platform.

A named pipe would do, but Linux pipes are not named. A message queue on Linux would do, too, but Windows has no such thing. TCP could be used, but that would make all those Windows application firewalls go frenzy. Gcc allows shared variables between processes, but that is compiler-specific and OS-specific in addition. A shared memory page could be used, but again, this is very OS-dependent. Tempfiles have been discussed, but were turned down due to race conditions...
It is not so simple really.

DDE is a fat, clumsy pig (like most MS technologies), but at least it works 90% of the time, except for the occasional "cannot find file" error. And since we are using the wxWidgets thingie for DDE, it should run on Unix, too (honestly, I don't know, but the docs claim that it does).
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: File association to registry fails?
« Reply #18 on: January 04, 2006, 12:59:37 pm »
The problem with multiple instances is that we need a bulletproof way to hand the commandline from a new instance to the already running instance.
I didn't expected this post to turn in such a big discussion, but I understand the problem by now. I would like to add the following: Some time ago I had a similar problem: Inform another instance of an application and be cross-platform (at least win/linux) compatible. I solved it by using the settings file. I put a flag "another_instance" and an address to post messages to into the settings file on startup. On application exit both are reset to zero. Thus another instance first checks the "another_instance" flag and sends a message to the address (shared memory in that case) if appropriate. Of course there are unresolved issues as well: If the application crashes the "another_instance" is not reset and things. Also, the main application was required to cyclic check the shared memory (which was OK for my purpose anyway). However: That time it was the "simplest" way I could think of and the application had only "tool-character"...
DDE is a fat, clumsy pig (like most MS technologies), [...]
Right, :lol: :lol: :lol:.
Morten.
« Last Edit: January 04, 2006, 01:04:17 pm by MortenMacFly »
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: File association to registry fails?
« Reply #19 on: January 04, 2006, 01:24:42 pm »
Quote
I solved it by using the settings file. I put a flag "another_instance" and an address to post messages to into the settings file on startup.
This is almost certain to fail one day. It might appear to work for a while, but one day, it will fail. And the bad thing is when it happens, you will not know why, because you forgot about it a long time ago...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: File association to registry fails?
« Reply #20 on: January 04, 2006, 01:49:22 pm »
This is almost certain to fail one day. [...]
True, but it works in a multi-user/multi-OS environment... :wink: But honestly: I agree (as I said). I've added this post because it might be the source for another (better) idea... just collecting ideas and it's pros/cons here...
Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #21 on: January 04, 2006, 02:11:02 pm »
Quote
The problem with multiple instances is that we need a bulletproof way to hand the commandline from a new instance to the already running instance. Unluckily, this is not precisely trivial to implement cross-platform.
When I start firefox with the option -url "my.html" or firefox -url "www.codeblocks.org" it also hands it over to the already running instance. But maybe there's different code for that according to the operating  system. So not portable then. (maybe for us : ifdef wxWIN, have seen it in other cb sources also).

Quote
except for the occasional "cannot find file" error.
Thomas, you're lucky, at my system it is NOT occasional, it's always. :-(
Really, maybe not top priority, but suppose you use an editor program and when you click on every .txt file, you get error messages ... you wouldn't like it.
Therefor , all ideas and knowledge that might help bring it on, I'll try to study it or help others.


[EDIT] : Registry code --> platform dependent, but apparantly DDE : platform independent ??
« Last Edit: January 04, 2006, 02:33:46 pm by killerbot »

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: File association to registry fails?
« Reply #22 on: January 04, 2006, 02:45:56 pm »
Hmm... This might be a bit obvious, but if Firefox manages to get this to work, and is both cross-platform (or at least has implementations for lots of platforms) and Open Source...

Unfortunately, I don't have time to go digging through its sources right now. If anyone has any time left to fill, though...

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: File association to registry fails?
« Reply #23 on: January 04, 2006, 05:34:28 pm »
I have an idea...

make a "Codeblocks_starter.exe" that will search the current processes for codeblocks.exe, and if there's one, try to communicate with it and tell it to open the file.

The problem is the how :P. I think using a TCP port for it (there was a wxTCPserver or something for inter-process communication) would be fine. This way, if there are TWO instances of codeblocks, the starter can ask you which instance you want to open the file with.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #24 on: January 04, 2006, 05:36:09 pm »
M$ devstudio has a special starter app, so I think they do it the way Rick is suggesting.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: File association to registry fails?
« Reply #25 on: January 04, 2006, 05:39:56 pm »
I remember seeing that "Couldn't find file" message sometimes and solved it by adding double quotes around the %1 in the registry. Dunno if it's the same problem you're discussing and that solution will do in your case.

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: File association to registry fails?
« Reply #26 on: January 04, 2006, 05:49:54 pm »
...
Quote
except for the occasional "cannot find file" error.
... at my system it is NOT occasional, it's always...
i had this too and posted a procedure how to get rid of already ...
http://forums.codeblocks.org/index.php?topic=1569.0

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: File association to registry fails?
« Reply #27 on: January 04, 2006, 05:50:46 pm »
I remember seeing that "Couldn't find file" message sometimes and solved it by adding double quotes around the %1 in the registry. Dunno if it's the same problem you're discussing and that solution will do in your case.
Hmm... mine already has double quotes...

i had this too and posted a procedure how to get rid of already ...
That gets rid of the error message, but it defeats DDE. At least for me, DDE does not work at all without the reg keys.
« Last Edit: January 04, 2006, 05:53:54 pm by thomas »
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: File association to registry fails?
« Reply #28 on: January 04, 2006, 06:13:36 pm »
i had this too and posted a procedure how to get rid of already ...
That gets rid of the error message, but it defeats DDE. At least for me, DDE does not work at all without the reg keys.
it's a workaround until someone (you) could fix this bug  :lol:

btw i've updated my experiences with this and wrote a small summary:
http://forums.codeblocks.org/index.php?topic=1569.msg14201#msg14201

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #29 on: January 04, 2006, 07:29:09 pm »
what does the run dde server means ??
IS this extra code inside CB running to catch the dde messages or something like that ??

[EDIT] Some info :

http://www.lugaru.com/man/File.Associations.and.DDE.html

http://www.dec.ctu.edu.vn/cit/tailieu/books/insidewin98/ch16/ch16.htm
« Last Edit: January 04, 2006, 07:34:04 pm by killerbot »