Reading a Specific Key String from ini File

Article Tools

The GetPrivateProfileString function Retrieves a string from the specified section in an initialization file.

API Syntax :

DWORD GetPrivateProfileString(

LPCTSTR lpAppName,
LPCTSTR lpKeyName,
LPCTSTR lpDefault,
LPTSTR lpReturnedString,
DWORD nSize,
LPCTSTR lpFileName

);

Parameters :

clip_image001 lpAppName – [in] The name of the section containing the key name. If this parameter is Null, the GetPrivateProfileString function copies all section names in the file to the supplied buffer.

clip_image001[1] lpKeyName – [in] The name of the key whose associated string is to be retrieved. If this parameter is Null, all key names in the section specified by the lpAppName parameter are copied to the buffer specified by the lpReturnedString parameter.

clip_image001[2] lpDefault – [in] A default string. If the lpKeyName key cannot be found in the initialization file, GetPrivateProfileString copies the default string to the lpReturnedString buffer. If this parameter is Null, the default is an empty string, “”.

clip_image001[3] lpReturnedString – [out] buffer that receives the retrieved string.

clip_image001[4] nSize – [in] The size of the buffer pointed to by the lpReturnedString parameter, in characters.

clip_image001[5] lpFileName – [in] The name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory.

Return Value : I The return value is the number of characters copied to the buffer, not including the terminating null character.

If neither lpAppName nor lpKeyName is Null and the supplied destination buffer is too small to hold the requested string, the string is truncated and followed by a null character, and the return value is equal to nSize minus one.

If either lpAppName or lpKeyName is Null and the supplied destination buffer is too small to hold all the strings, the last string is truncated and followed by two null characters. In this case, the return value is equal to nSize minus two.

Extern.Declare micLong, "GetPrivateProfileString", "kernel32.dll", "GetPrivateProfileStringA", _
    micString, micString, micString, micString + micByRef, micDWord, micString

Retval = Extern.GetPrivateProfileString( "TD Api Server", "MAPI_Mail_Profile", "not found", returnString, 256, "mercury.ini" )
If retval > 0 Then
   Print "Buffer Size = " & retval
   Print "MAPI_Mail_Profile = " & returnString
End If
Previous postWhat is the Last Window Opened? Next postProblem - Retrieve all Sections from ini File

Related Posts

Post Your Comment

You must be logged in to post a comment.