这是一个能够读取ini文件中的 Section Name 和各个KEY 值的函数。自知多有纰漏,还望指正。
(注:之前的代码过于繁琐。在下已于1.27 进行了修改。简化重复代码和注释,减少了超过30%的代码量。)
函数的具体定义参考MSDN定义:
https://msdn.microsoft.com/en-us/library/ms724353(VS.85).aspx
程序具体功能部分摘录如下:
GetPrivateProfileString function
Retrieves a string from the specified section in an initialization file.
Note This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry.
Syntax
DWORD WINAPI GetPrivateProfileString(
_In_ LPCTSTR lpAppName,
_In_ LPCTSTR lpKeyName,
_In_ LPCTSTR lpDefault,
_Out_ LPTSTR lpReturnedString,
_In_ DWORD nSize,
_In_ LPCTSTR lpFileName
);
Parameters
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, "".
Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedStringbuffer to strip any trailing blanks.
A pointer to the buffer that receives the retrieved string.
The size of the buffer pointed to by the lpReturnedString parameter, in characters.