Looks nice IanM. I might switch to those in the future if the kernel32 calls get too slow (right now they just happen on startup and exit, so there's not much of a noticeable time drag).
I generally use the following functions to call kernel32.dll. Note that these require the loading of kernel32.dll as follows.
Enable (load kernel32.dll)
global kernel32num
kernel32num = 5 `any open dll number will work
load dll "kernel32.dll",kernel32num
Functions:
function readINIstring(full_filename as string,section as string,keyname as string,default as string)
local returnval as string
returnval = space$(1024)
call dll kernel32num,"GetPrivateProfileStringA",section,keyname,default,returnval,1024,full_filename
endfunction returnval
function writeINIstring(full_filename as string,section as string,keyname as string,value as string)
call dll kernel32num,"WritePrivateProfileStringA",section,keyname,value,full_filename
endfunction
function readINIint(full_filenamea as string,sectiona as string,keynamea as string,defaulta as integer)
local returnval as integer
returnval = advVal(readINIstring(full_filenamea,sectiona,keynamea,str$(defaulta)),defaulta)
endfunction returnval
function writeINIint(full_filenamea as string,sectiona as string,keynamea as string,valuea as integer)
writeINIstring(full_filenamea,sectiona,keynamea,str$(valuea))
endfunction
function writeINIsection(full_filename as string,section as string,values as string)
call dll kernel32num,"WritePrivateProfileSectionA",section,values,full_filename
endfunction
function readINIcolor(full_filenamea as string,sectiona as string,basekeyname as string)
local returnval as dword
returnval = rgb(readINIint(full_filenamea,sectiona,basekeyname+"R",128),readINIint(full_filenamea,sectiona,basekeyname+"G",128),readINIint(full_filenamea,sectiona,basekeyname+"B",128))
endfunction returnval
function createINIfont(full_filenamea as string,sectiona as string,basekeyname as string)
local returnval
returnval = createFont(readINIstring(full_filenamea,sectiona,basekeyname+"FONT","Arial"),readINIint(full_filenamea,sectiona,basekeyname+"SIZE",10),readINIint(full_filenamea,sectiona,basekeyname+"BOLD",0),readINIint(full_filenamea,sectiona,basekeyname+"ITAL",0),readINIint(full_filenamea,sectiona,basekeyname+"UNDL",0))
endfunction returnval
function readINInumberedString(full_filenamea as string,sectiona as string,basekeyname as string,numval,defaultend as string)
local returnval as string
returnval = readINIstring(full_filenamea,sectiona,basekeyname+str$(numval),defaultend)
if returnval=defaultend
returnval = readINIstring(full_filenamea,sectiona,basekeyname+"0"+str$(numval),defaultend)
if returnval=defaultend
returnval = readINIstring(full_filenamea,sectiona,basekeyname+"00"+str$(numval),defaultend)
if returnval=defaultend
returnval = readINIstring(full_filenamea,sectiona,basekeyname+"000"+str$(numval),defaultend)
endif
endif
endif
endfunction returnval
function advVal(intstring as string,default as integer)
local returnval as integer
local p
local err
err = 0
for p = 1 to len(intstring)
if mid$(intstring,p)<>"0" and mid$(intstring,p)<>"1" and mid$(intstring,p)<>"2" and mid$(intstring,p)<>"3" and mid$(intstring,p)<>"4" and mid$(intstring,p)<>"5" and mid$(intstring,p)<>"6" and mid$(intstring,p)<>"7" and mid$(intstring,p)<>"8" and mid$(intstring,p)<>"9" and (mid$(intstring,p)<>"-" or p<>1) then err = 1
next p
if err=0
returnval = val(intstring)
else
returnval = default
endif
endfunction returnval