Option explicit on
Module ini
'Ini Cont. bas ver 1.0 + A ini '==================================== ==========================================
'Getintfromini (sectionname, keyname, defaultvalue, inipath)
'
'Sectionname: node name
'Keyname: configuration item name
'Defaultvalue: Default Value
'Inipath: ini configuration file path
'
'================================================ ==================================
// Declare the system function for retrieving the value of a configuration item of the int type from the ini configuration file
Private declare function getprivateprofileint lib "Kernel32" alias "getprivateprofileinta" (byval lpappname as string, byval lpkeyname as string, byval ndefault as integer, byval lpfilename as string) as integer
// Declare a system function that obtains the value of a string-type configuration item from the ini configuration file
Private declare function getprivateprofilestring lib "Kernel32" alias "inline" (byval lpappname as string, byval lpkeyname as string, byval lpdefault as string, byval lpreturnedstring as string, byval nsize as integer, byval lpename
As string) as integer
// Declare the system function that writes the value of a string-type configuration item to the ini configuration file.
Private declare function writeprivateprofilestring lib "Kernel32" alias "writeprivateprofilestringa" (byval lpappname as string, byval lpkeyname as string, byval lpstring as string, byval lpfilename as string) as integer
// Obtain the value of the int type configuration item from the ini configuration file
Public Function getintfromini (byval sectionname as string, byval keyname as string, byval defaultvalue as integer, byval inipath as string) as integer
Getintfromini = getprivateprofileint (sectionname, keyname, defaultvalue, inipath)
End Function
// Obtain the value of a string-type configuration item from the ini configuration file
Public Function getstrfromini (byval sectionname as string, byval keyname as string, byval defaultvalue as string, byval inipath as string) as string
Dim buffer as string
Dim RC as integer
Buffer = space (0, 256)
Rc = getprivateprofilestring (sectionname, keyname, defaultvalue, buffer, buffer. length, inipath)
Getstrfromini = left (buffer, instr (buffer, vbnullchar)-1)
End Function
// Write the string-type configuration item value to the ini configuration file
Public Function writestrini (byval sectionname as string, byval keyname as string, byval setvalue as string, byval inipath as string) as integer
Dim RC as integer
Rc = writeprivateprofilestring (sectionname, keyname, setvalue, inipath)
If RC then
Rc = 1
End if
Writestrini = RC
End Function
End Module