Declare Function GetProfileString Lib "kernel32.dll" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long
GetProfileString reads an string value from the WIN.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. This function is basically a watered-down version of GetPrivateProfileString because it, unlike this function, works with all INI files.
Example:
' Read the value "Wallpaper" under the [Desktop] section of WIN.INI
Dim buffer As String * 255
x = GetProfileString("Desktop", "Wallpaper", "(error)" buffer, 255)
retstr = Left(buffer, x) ' extract string
If retstr = "(error)" Then
Debug.Print "Wallpaper not found"
Else
Debug.Print "The wallpaper is " retstr
End If
Related Call: GetPrivateProfileString, GetProfileInt, WriteProfileString
Category: INI Files
Back to the index.