Page 1 of 1

ini file usage

Posted: Wed Aug 13, 2003 12:13 pm
by waffle
after tinkering with the OpenPreferences function, i found it lacks some of the functionality of the api calls. So i converted my code to use the api.

this applies to windows only. Fred probably did his function to support linix and windows, which would explain the problem. The exact problem was that once i created my pref file, i could not make changes unless i deleted the file. The api does not require that. Here is how to use the api:

Code: Select all

#BufferSize=1000
Global *FileBuffer ;so it can be used inside any function
*FileBuffer = AllocateMemory(#BufferSize)

;other vars used by API
;these can be declared inside functions as required
IniFileName.s="MyIni.INI"
Section.s="First User"
KeyName.s="First Key"

;write a string to the ini file
WritePrivateProfileString_(Section, KeyName, "Data!", IniFileName)

;Read a string
GetPrivateProfileString_(Section, KeyName, "Default", *FileBuffer, MemorySize(*FileBuffer), IniFileName)
KeyData.s=PeekS(*FileBuffer)
Debug KeyData

;Read a long or int
KeyName="Key Int"
KeyVal.l=GetPrivateProfileInt_(Section,KeyName, 0, IniFileName)

;Write a long or int(this gets slightly odd)
WritePrivateProfileString_(Section,KeyName,Str(KeyVal),IniFileName)
I find this method easier than freds method, but his will also support linix while this will not.

Posted: Mon Aug 18, 2003 5:43 pm
by naw
Yep - I had the same problem with Windows last year & reported it under Bugs, but I guess its a feature not a bug ;-)

- if you use the Preferences Library for *doing* INI files, and Open a file for Writing, the first time you write an entry, it removes everything else. I would have expected it to overwrite the entry (not trash the file) - ho-hum!

The Windows API commands don't suffer the same problem...