Page 1 of 1 1
Topic Options
#194343 - 2009-06-23 12:36 AM Windows 7 Beta - ReadProfileString
NZBluefish Offline
Just in Town

Registered: 2009-06-23
Posts: 3
Loc: NZ
Hi All,

I was playing around with KiXtart on a Windows 7 Beta test machine yesterday and noted that the call return behaviour for ReadProfileString seems to be different.

If either the section or key are missing you get a returncode of 2 instead of 0.

Probably no big deal at the moment since Win7 isn't out there yet, but if this behaviour is the same in the general release, then scripts expecting to always get back a returncode of 0 when a key isn't present, but that also test for a non-zero rc might not work the same anymore.

Has anyone else tried this on Win7 and got the same result?

Cheers.

Top
#194350 - 2009-06-23 01:33 PM Re: Windows 7 Beta - ReadProfileString [Re: NZBluefish]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
If you will provide some test code, I will verify your findings.
Top
#194512 - 2009-07-01 01:44 AM Re: Windows 7 Beta - ReadProfileString [Re: Allen]
NZBluefish Offline
Just in Town

Registered: 2009-06-23
Posts: 3
Loc: NZ
Hi Allen. Apologies for the delayed reply. Taking some leave finally!

Here is some test code and the sample output from running on a Win7 Beta test machine and a WinXP machine. Hope this is useful. Cheers, Innes

Ini file used for testing:

 Code:
[TESTSECT1]
SOMEKEY1=ABCXYZ
[TESTSECT2]


Test script code:

 Code:
; **** Testing READPROFILESTRING in Windows 7 - Build 7000

? "ReadProfTest running on @PRODUCTTYPE"

$iniFile = "c:\scratch\Win7test.ini"

; Test 1 - Section and key present

$val = ReadProfileString($iniFile,"TESTSECT1","SOMEKEY1")
? "Test 1 Results - file, section, key present."
? "   Key Value = $val"
? "   ERROR:  @ERROR"
? "   SERROR: @SERROR"

; Test 2 - Section present but key absent

$val = ReadProfileString($iniFile,"TESTSECT2","NOKEYFND")
? "Test 2 Results - key absent."
? "   Key Value = $val"
? "   ERROR:  @ERROR"
? "   SERROR: @SERROR"

; Test 3 - Section and key absent

$val = ReadProfileString($iniFile,"NOSECTFND","NOKEYFND")
? "Test 3 Results -  Section and key absent."
? "   Key Value = $val"
? "   ERROR:  @ERROR"
? "   SERROR: @SERROR"

; Test 4 - No ini file found

$val = ReadProfileString("C:\NOSUCHFILE.INI","TESTSECT","TESTKEY")
? "Test 4 Results - INI file missing."
? "   Key Value = $val"
? "   ERROR:  @ERROR"
? "   SERROR: @SERROR"


Output from Win7 Beta - Bld 7000

ReadProfTest running on Windows Vista Ultimate Edition
Test 1 Results - file, section, key present.
Key Value = ABCXYZ
ERROR: 0
SERROR: The operation completed successfully.
Test 2 Results - key absent.
Key Value =
ERROR: 2
SERROR: The system cannot find the file specified.
Test 3 Results - Section and key absent.
Key Value =
ERROR: 2
SERROR: The system cannot find the file specified.
Test 4 Results - INI file missing.
Key Value =
ERROR: 2
SERROR: The system cannot find the file specified.


Output from WinXP SP3 Test:

ReadProfTest running on Windows XP Professional
Test 1 Results - file, section, key present.
Key Value = ABCXYZ
ERROR: 0
SERROR: The operation completed successfully.
Test 2 Results - key absent.
Key Value =
ERROR: 0
SERROR: The operation completed successfully.
Test 3 Results - Section and key absent.
Key Value =
ERROR: 0
SERROR: The operation completed successfully.
Test 4 Results - INI file missing.
Key Value =
ERROR: 0
SERROR: The operation completed successfully.

Top
#194513 - 2009-07-01 04:14 AM Re: Windows 7 Beta - ReadProfileString [Re: NZBluefish]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
I'm getting the same results as you (on XP 32bit and Win7 RC1 64bit)... however, I have to say, unless I am completely overlooking something, I think the XP results are completely off, and the Win 7 are better, but the errors are not very specific. I tested this with 4.22 and the results were like this way back then too.

There are a number of EnumINIs in the UDF forum, one in particular Glenn wrote... http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=135385 I notice the way he wrote it, it completely works around this behavior AND actually gives a meaningful error.

I rarely use INI files... but Glenn uses them all the time. I'd be interested in hearing his thoughts.

Top
#194514 - 2009-07-01 04:48 AM Re: Windows 7 Beta - ReadProfileString [Re: Allen]
NZBluefish Offline
Just in Town

Registered: 2009-06-23
Posts: 3
Loc: NZ
I would agree that the Win7 behaviour seems more appropriate. It would be better to have the call indicate missing data so that the user can then determine what action to take. As it stands you get the same return for a defined key with no value as you do for a completely absent key.

A useful return would indicate whether the file, section or key are absent.

As an aside, given my recent introduction to KiXtart, what is your preferred method of storing config data if you rarely use INI files in this way.

Cheers, Innes

Top
#194515 - 2009-07-01 05:06 AM Re: Windows 7 Beta - ReadProfileString [Re: NZBluefish]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
Most of my scripts these days are simple logon scripts, which there is little need for a ini file. Depending on the task, sometimes I just use the registry.
Top
#194578 - 2009-07-04 02:54 PM Re: Windows 7 Beta - ReadProfileString [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4557
Loc: USA
@Glenn, just wondering if you looked at this?
Top
#194579 - 2009-07-04 04:50 PM Re: Windows 7 Beta - ReadProfileString [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4400
Loc: New Jersey
Will in the next day or so - been busy preparing for an Independence day/graduation party. \:\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#202352 - 2011-05-26 04:53 PM Re: Windows 7 Beta - ReadProfileString [Re: Glenn Barnas]
Ruud van Velsen Moderator Offline
Developer
*****

Registered: 1999-05-06
Posts: 391
Loc: Amsterdam, The Netherlands
Phhh... just saw this one. Yes, good one... this is, for lack of a better description, a "progression" in Windows 7 (as opposed to a regression...).

W7 contains a fix for the age-old issue in the GetPrivateProfileString() API that it never sets the error code as documented in the specifications.

In theory, I could make KiX act on W7 like it was on XP, and drop the error code on the floor, but that does not sound like the right thing to do.

So, yes, this is an unexpected side-effect when running KiX on Windows 7, and I suggest to handle it in the scripts where appropriate.

Thanks for the report!

Ruud

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 676 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.092 seconds in which 0.064 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org