Declare Function GetPrivateProfileString Lib "kernel32.dll" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
GetPrivateProfileString reads an string value from any INI file. The parameters passed to the function specify which value will be read from. The function always returns the length in characters of the string put into the variable passed as lpReturnedString. If the function was successful, the string read from the INI file will be put into lpReturnedString. If not, it will instead receive the string given as lpDefault.
Example:
' Read the value "scrnsave.exe" under the [boot] section of SYSTEM.INI
' These next few lines get the Windows directory....
Dim buffer As String * 255
x = GetWindowsDirectory(buffer, 255)
sysini = Left(buffer, x) & "\system.ini"
' Now read the value
x = GetPrivateProfileString("boot", "scrnsave.exe", "(error)" buffer, 255, sysini)
retstr = Left(buffer, x) ' extract string
If retstr = "(error)" Then
Debug.Print "Screen saver not found"
Else
Debug.Print "The screen saver is " retstr
End If
Related Calls: GetPrivateProfileInt, GetProfileString, WritePrivateProfileString
Category: INI Files
Back to the index.