Open Rails

NativeMethods.GetPrivateProfileString Method

[This is preliminary documentation and subject to change.]

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

[PreserveSig]
[DllImport(EntryPoint=""GetPrivateProfileString"", CharSet=CharSet.Unicode, SetLastError=True, ExactSpelling=False, PreserveSig=True, CallingConvention=CallingConvention.Winapi, BestFitMapping=False, ThrowOnUnmappableChar=False, Value=""kernel32.dll"")]
public static int GetPrivateProfileString(
   string sectionName,
   string keyName,
   string defaultValue,
   string value,
   int size,
   string fileName
);

Parameters

sectionName
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.
keyName
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 sectionName parameter are copied to the buffer specified by the value parameter.
defaultValue
A default string. If the keyName key cannot be found in the initialization file, GetPrivateProfileString copies the default string to the value buffer. If this parameter is null, the default is an empty string, "". Avoid specifying a default string with trailing blank characters. The function inserts a null character in the value buffer to strip any trailing blanks.
value
A pointer to the buffer that receives the retrieved string.
size
The size of the buffer pointed to by the value parameter, in characters.
fileName
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

The return value is the number of characters copied to the buffer, not including the terminating null character. If neither sectionName nor keyName 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 size minus one. If either sectionName or keyName 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 size minus two. In the event the initialization file specified by fileName is not found, or contains invalid values, this function will set errorno with a value of '0x2' (File Not Found). To retrieve extended error information, call GetLastError.

See Also

NativeMethods Class | ORTS.Common Namespace