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

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
File association to registry fails?
« on: January 03, 2006, 10:25:43 am »
Dear all,
due to a computer crash I had to re-install everything from scratch. I compiled rev. 1648 and run it but I encounter problems with setting the file association. After the question: "Code::Blocks is not currently the default application for C/C++ source files Do you want to set it as default?" I receive a lot of errors like:
Code
10:06:05: Can't create registry key 'HKCR\.cbp' (error 5: access denied)
10:06:05: Can't open registry key 'HKCR\.cbp' (error 2: file not found)
10:06:05: Can't set value of 'HKCR\.cbp' (error 2: file not found)
when I click OK. Please notice that I am no longer an administrator on my machine (I am a power user by now) and that the path to the registry is not correct. Instead "HKCR\.cbp" it should be something like: "HKLM\.cbp". But there I might have no access, which should be taken care of anyway (I believe). Can someone confirm this issue?

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 MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: File association to registry fails?
« Reply #1 on: January 03, 2006, 10:36:09 am »
Additional info:
I ran CodeBlocks as an admin for one time by now. The file association works then - the keys are registered correctly under HKLM. But when I start CodeBlocks after that as a power user again I receive the same errors as before. This leads to the question: Why is (obviously) HKCR being checked and tried to be modified if I run as power user and HKLM (the correct one) only if I run C::B as admin? Shouldn't HKLM be the only one key to be read/modified for the file association to work?
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 #2 on: January 03, 2006, 10:38:11 am »
It's because you are not admin !
I have created a patch (assigned it to Thomas, so if you kindly ask him, he might apply it ;-)  )
See here :
http://forums.codeblocks.org/index.php?topic=1793.msg13435#msg13435

Patch you can find at sourceforge and the in the forum topic , listing the community patches.

Lieven

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: File association to registry fails?
« Reply #3 on: January 03, 2006, 10:47:57 am »
He might not, because he knows too little about the magic incantations of the registry and he is afraid of completely breaking it. :lol:

From what he has read in another thread, there seems to be a user section in Windows98, but apparently it is not used...?
Until someone who really knows how to make it work on every system, Thomas is very reluctant to touch anything, lest it breaks for the systems where it works, too.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #4 on: January 03, 2006, 10:50:37 am »
That's true Thomas.
Can anyone with WIN98 try the patch out please ???

Making the patch a bit more complicated I could check on the windows version, but would be nicer if it already works as it is now.

Cheers,
Lieven

grv575

  • Guest
Re: File association to registry fails?
« Reply #5 on: January 03, 2006, 12:22:29 pm »
Code
10:06:05: Can't create registry key 'HKCR\.cbp' (error 5: access denied)
10:06:05: Can't open registry key 'HKCR\.cbp' (error 2: file not found)
10:06:05: Can't set value of 'HKCR\.cbp' (error 2: file not found)

shouldn't that be HKCU?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #6 on: January 03, 2006, 12:32:47 pm »
HKCR : class root
HKCU : current user

It should be CU, well in more modern windowsez, but we have to make sure it also works on win95/98/Me/NT4 

So my simple patch at this moment looks if the
user key exists, if so -> put the stuff there (so that fixes win 200 /xp /2003), and if that one does not exist, put it at class root.
For this to work : the other os's should not have the user key.
It seems Win98 does has it, the BIG question is, if we also store the info at the user key, will it be used by the OS.

It seems the user key was only added in win2000, but it is possible the older os's also have because of upgrades ??

Note : we have not played all our cards yet, so if this simple fix does not work I can explicitly go check on the windows version.

Lieven

grv575

  • Guest
Re: File association to registry fails?
« Reply #7 on: January 03, 2006, 12:40:11 pm »
Well, windows2000 is a merge of win98 features on top of nt.  So it could be that win98 had it first and then it was added to win2000.  I'm pretty sure that it would work if it's present.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #8 on: January 04, 2006, 09:16:45 am »
We are going to do a test on win98 soon with my patch.
So I will provide a special build for that, there are 2 open questions :

1) who added the DDE stuff to the associations.cpp -> as mentioned in another post, this is "probably" NOT needed, the command entry is sufficient, and this is the cause of the "double click on a cbp file" bug.

2) what is that extra library I need to linkt with so that the svn builds work on Win98 ? And will those ancient windows versions run an unicode build ??

thanks for the info,
Lieven

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: File association to registry fails?
« Reply #9 on: January 04, 2006, 09:53:33 am »
1) who added the DDE stuff to the associations.cpp -> as mentioned in another post, this is "probably" NOT needed, the command entry is sufficient, and this is the cause of the "double click on a cbp file" bug.

I did. DDE is useful when you want to re-use an already existing instance (i.e. not start a new instance of C::B).
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #10 on: January 04, 2006, 09:57:34 am »
Do you think we really need it Yiannis, that DDE ? I checked some other software (adobe, firefox, skype, ..), they all seem to stick to just the command stuff.
Do you mean by this, if you have two 2 different cb exe's on your pc, both will use the same settings, cause what i see now is that there's a ping-pong game going on between the devel-exe and the output-exe.

Quote
would you be so kind and add SHFolder(before Shell32) to the link libraries of the sdk target for your builds - then Codeblocks could be used on W98 again.
Yiannis, is this something that always can be added ? Or does it create conflicts on the non win98 builds ? If it can always be added, then we have a build that also works for win98/95, otherwise we need a special build/target for those 2 platforms.


Lieven

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: File association to registry fails?
« Reply #11 on: January 04, 2006, 10:36:17 am »
Do you think we really need it Yiannis, that DDE ? I checked some other software (adobe, firefox, skype, ..), they all seem to stick to just the command stuff.
If you have a solution that can do without DDE then please step forward.
DDE never really works 100%, so I would be very happy to see it gone. But if you don't use DDE, then how do you get documents which you double-click in Explorer to open in the already running instance instead of starting a new one?
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #12 on: January 04, 2006, 11:45:07 am »
Ah, thanks, that's what it is for.

Have done some searching in the meantime.
At my system : .html --> FireFoxHtml -> only command
When I click several .html files in explorer thay all open up in the same firefox (in sereperate tabs).
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 ? Any experts around here ?

I have installed as a text editor editpadlite (www.editpadlite.com), which handles the .txt files -> all open up in the same editpadlite (I think this one only allows one instance of it's application, so might be easy like that).


Note : I don't have anything against the DDE, but when you double click the files CB should handle and you get that annoying error message, then I'd suggest that we take it out for the moment, since it does not give a solid user experience.
[EDIT] well as long as RC3 is not out, it does not yet give the 'official' users this bad experience

Lieven
« Last Edit: January 04, 2006, 11:51:22 am by killerbot »

Offline Der Meister

  • Regular
  • ***
  • Posts: 307
Re: File association to registry fails?
« Reply #13 on: January 04, 2006, 11:53:24 am »
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.
Real Programmers don't comment their code. If it was hard to write, it should be hard to understand.
Real Programmers don't write in BASIC. Actually, no programmers write in BASIC, after the age of 12.

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: File association to registry fails?
« Reply #14 on: January 04, 2006, 11:54:40 am »
Have done some searching in the meantime.
At my system : .html --> FireFoxHtml -> only command
When I click several .html files in explorer thay all open up in the same firefox (in sereperate tabs).
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 ? Any experts around here ?

I'm by no means an expert, but it seems Firefox always starts an extra instance.
Presumably it then signals the existing instance somehow, because that one then opens the file or empty window, while the extra instance closes.

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 »

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #30 on: January 04, 2006, 08:35:12 pm »
some more test results :
1) on my laptop everything works ok
2) on my pc NOT
 a) when I have CB open, and i double click for example on a cpp file -> opens nicely in CB
 b) when no CB open, double click oncpp file -> that F*** error message box

so it seems we have ?sometimes? a problem with DDE if the app is not running yet, and then it probably falls back to the command version which opens the file in CB then ?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #31 on: January 04, 2006, 08:53:18 pm »
could not modify my previous post anymore, weird.

Some more info : I changed the command subkey from :

"D:\work\cb_snap\src\devel\codeblocks.exe" "%1"

to :

"D:\work\cb_snap\src\devel\codeblocks.exe" "test.cpp"

So I could check if DDE would fall back on this, it seems NOT, since I still get the error message on the file I double clickd (which wasn't test.cpp ;-)  )

[EDIT] : nope I was wrong, CB started but the clicked file was not opened any more, why because it now wanted to open the test.cpp, which did not exist, so in the end it did fall back on the command subkey.

But just before this fallback we get this error message, i wonder who gives this : DDE/Windows or CB ?

Now the following is also rather unclear, comes from :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_extending/fileassociations/fa_verbs.asp

Quote
ifexec. Set the default value of this subkey to the DDE command to be used if DDE conversation cannot be initiated. When initiation fails, the application specified by the default value of the verb's command subkey is launched (SO IS IT THIS ???????). If an ifexec key exists, its default value will then be used as the DDE command. If there is no ifexec subkey, the default value of the ddeexec key is used again as the DDE command(OR IS IT THIS ?????).
« Last Edit: January 04, 2006, 09:01:19 pm by killerbot »

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: File association to registry fails?
« Reply #32 on: January 04, 2006, 09:00:33 pm »
... continueing my search ...
it also depends, if you have the DDE server in CB enabled or not

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5496
Re: File association to registry fails?
« Reply #33 on: January 04, 2006, 09:03:15 pm »
yes, it is enabled

grv575

  • Guest
Re: File association to registry fails?
« Reply #34 on: January 04, 2006, 11:21:37 pm »
The code is already special cased for windows vs. linux, so why not use the appropriate linux IPC mechanism on linux and windows IPC code on windows?  Whether it be mailboxes, message queues, named pipes, mmap(), etc - this is all very os-specific anyway since they're typicall os & middleware building blocks.  If dde is unreliable....