Sign in to follow this  
Followers 0
MSLx Fanboy

INI file functions

10 posts in this topic

Is there a reason why file handles are not acceptable for INIRead and INIWrite functions?

;;This works

$output = IniRead("C:\Windows\avrack.ini", "Settings", "Volume", "")
MsgBox(0, "test", $output & @CRLF & @ERROR)

;;This doesn't
$file = FileOpen("C:\Windows\avrack.ini", 0)
$output = IniRead($file, "Settings", "Volume", "")
$output = IniRead("C:\Windows\avrack.ini", "Settings", "Volume", "")
MsgBox(0, "test", $output & @CRLF & @ERROR)
FileClose($file)

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Possibly because the FileOpen already has the file open, so the parts of IniRead/IniWrite that open the file are blocked?

Edit: They'd be stepping on each other's I/O.

Edited by c0deWorm

My UDFs: ExitCodes

Share this post


Link to post
Share on other sites

Is there a reason why file handles are not acceptable for INIRead and INIWrite functions?

;;This works

$output = IniRead("C:\Windows\avrack.ini", "Settings", "Volume", "")
MsgBox(0, "test", $output & @CRLF & @ERROR)

;;This doesn't
$file = FileOpen("C:\Windows\avrack.ini", 0)
$output = IniRead($file, "Settings", "Volume", "")
$output = IniRead("C:\Windows\avrack.ini", "Settings", "Volume", "")
MsgBox(0, "test", $output & @CRLF & @ERROR)
FileClose($file)

<{POST_SNAPBACK}>

Why do you need the handle for read an INI file?

Simply, just compare the documentation: About IniRead page says :

IniRead ( "filename", "section", "key", "default" )

not like FileRead , the syntax is:

FileRead ( filehandle or "filename", count )

Mainly, IniRead wasn't designed for use file handles.

Share this post


Link to post
Share on other sites

Is there a reason why file handles are not acceptable for INIRead and INIWrite functions?

because IniRead() and IniWrite() are not implemented to accept a file handle. See source code script_file.cpp AutoIt_Script::F_IniRead.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

I know according to the help file that one says that file handles are permitted the other does not. My question is, Why not?

If I can start learning more advanced C++ programming techniques, I might try to work on that code (just a wee bit).


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

I know according to the help file that one says that file handles are permitted the other does not.  My question is, Why not?

If I can start learning more advanced C++ programming techniques, I might try to work on that code (just a wee bit).

<{POST_SNAPBACK}>

The INI functions wrap underlying INI-related Windows API calls. Unless you are prepared to write your own INI reading/writing code and re-implement all of it, there is no point (or sense) in making the INI functions accept a file handle.

Share this post


Link to post
Share on other sites

I know according to the help file that one says that file handles are permitted the other does not.  My question is, Why not?

<{POST_SNAPBACK}>

Writing to an INI file is similar to writng to registry. Both IniWrite and RegWrite are more related to each other then as to FileWrite. You cannot have a handle for RegWrite? So IniWrite should not have one.

Share this post


Link to post
Share on other sites

And to confirm what MHz says, Microsoft agrees since they list the API functions for writing to INI files under the Registry section.

Share this post


Link to post
Share on other sites

Well to further concrete the idea of INI and Registry being related...

Before the Registry there were INI files. They became very numerous, and Micro$oft wanted a central place to configure applications. They came up with what is known to us today as the Registry.

*Disclaimer* Micro$oft may not have come up with the 'registry' idea, but they are certainly using it.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Ok, thanks, that would explain why. I'll stick with the existing code... :whistle:


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0