Registry reading bug with RegOpenKeyEx

Just starting out? Need help? Post your questions and find answers here.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Registry reading bug with RegOpenKeyEx

Post 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 ?
- Registered PB user -

Using PB 4.00
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

What is 'ret'? Shouldn't it be '@ret' or something...
Doobrey
Enthusiast
Enthusiast
Posts: 218
Joined: Sat Apr 26, 2003 4:47 am
Location: Dullsville..population: me
Contact:

Post 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.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post 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).
- Registered PB user -

Using PB 4.00
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post 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:
- Registered PB user -

Using PB 4.00
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Because it's copy/pasted from a C code :). Hopefully '\\' is like \ on windows.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post 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.
- Registered PB user -

Using PB 4.00
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

> next time i will ask before in beginner area.

That's easy to change... :D

Timo
quidquid Latine dictum sit altum videtur
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

thanks you freak :wink:

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

Using PB 4.00
oldefoxx
Enthusiast
Enthusiast
Posts: 532
Joined: Fri Jul 25, 2003 11:24 pm

Something Strange Going On Here

Post 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.
has-been wanna-be (You may not agree with what I say, but it will make you think).
Post Reply