Page 1 of 1

Registry reading bug with RegOpenKeyEx

Posted: Mon Aug 25, 2003 11:50 pm
by newbie
Hi,

at start i thought it was me who was doing things wrong, but after many try and the fact that i handled registry well without any problems in Visual Basic, i ended with the conclusion that there is a bug.

I'm just using the classic API, the first is :
RegOpenKeyEx_

Just with that, 9 time on 10 try the API failed to open, so all the following code can't work.
I tested in Visual Basic, the key is opened successfully each time, and in PureBasic, after many many try, suddently the key is opened successfuly, but doesn't work the most of time.

I simply use this line :
RegOpenKeyEx_( hKey, strPath, 0, #KEY_READ, Ret )
where "hkey" = #HKEY_LOCAL_MACHINE = $80000002

"strpath" = a valid existing path inthe registry
the API failed and take a value different than 0.

I'm using Windows XP + SP1 + all last update, CPU Athlon XP 2000+, chipset VIA KT400, PureBasic 3.72

Someone else can do the test on WinXP ?

Posted: Tue Aug 26, 2003 12:26 am
by Pupil
What is 'ret'? Shouldn't it be '@ret' or something...

Posted: Tue Aug 26, 2003 12:32 am
by Doobrey
Pupil wrote:What is 'ret'? Shouldn't it be '@ret' or something...
Spot on Pupil..
The last parameter should be a pointer to a variable that recieves the handle.

Posted: Tue Aug 26, 2003 1:43 am
by newbie
I tried with that too (to read Internet Explorer Path) :
Reg_Path.s = "SOFTWARE\\Classes\\Applications\\iexplore.exe\\shell\\open\\command"


IE_path.s
hKey.l
keyvalue.s = Space(512)
datasize.l = 512

res.l = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, Reg_Path, #NULL, #KEY_ALL_ACCESS, @hKey)
If res = 0
RegQueryValueEx_(hKey, "", 0, 0, @keyvalue, @datasize)
keyvalue = Left(keyvalue, datasize - 1)
RegCloseKey_(hKey)
Else
MessageRequester("Erreur", "La valeur dans la base de registre n'a pu être lue (" + IE_PATH + ")", #PB_MessageRequester_Ok)
EndIf
But same pb, doesn't work at all, and suddently after 10 or more try it works (verified each time with Debug).

Posted: Tue Aug 26, 2003 3:13 am
by newbie
hm, seems to work with this :
res.l=RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, @Reg_Path, #NULL, #KEY_READ, @hKey)

If res = 0 ; open success


type.l=0
keyvalue$=Space(255)
datasize.l=255
res.l = RegQueryValueEx_( hKey, @strValueName$, 0, @type, @keyvalue$, @datasize)
I'm still trying, but it seems good.

Sorry if it was not a bug, but in VB i didn't have to play with adresses, so i was a bit confused this time.

I will looking at for reg library to avoid to write such line :wink:

Posted: Tue Aug 26, 2003 11:38 am
by freak
Reg_Path.s = "SOFTWARE\\Classes\\Applications\\iexplore.exe\\shell\\open\\command"
Why do you use double \\ ? I always used single ones in the Registry, and
it worked fine.

Timo

Posted: Tue Aug 26, 2003 3:09 pm
by Fred
Because it's copy/pasted from a C code :). Hopefully '\\' is like \ on windows.

Posted: Tue Aug 26, 2003 3:51 pm
by newbie
because it wasn't working so i tried everything ;)
and "\\" are in C code and in "reg" file so it was just a test :oops:

now all works, sorry for this false report, next time i will ask before in beginner area.

Posted: Tue Aug 26, 2003 6:18 pm
by freak
> next time i will ask before in beginner area.

That's easy to change... :D

Timo

Posted: Tue Aug 26, 2003 7:32 pm
by newbie
thanks you freak :wink:

if you can realize all my wishes, i have a lot more for you :D

Something Strange Going On Here

Posted: Tue Aug 26, 2003 7:49 pm
by oldefoxx
Good catch about having \\ instead of \ in the path statements. I haven't used C in years, but recall that certain reserved symbols had to be entered twice to appear as themselves, which might explain the useage in C source.

However, what interests me is why the path with the '' pairing would ever work at all. If software is stable, you should get exactly the same results every time under the same conditions. Of course when we talk software here, we don't just mean PureBASIC, but the whole of the operating system. Someone else said it worked fine for them. I wonder if we chanced on something in the way of an indicator of sorts as to some deeper, more subtle differences in the systems being used. Perhaps different versions of windows working in slightly different fashions.

Not that I see any practical use for this, except to wonder why it does not always work the same way in the same environment.