C语言实现ini解析函数 getPrivateProfileString

这是一个能够读取ini文件中的 Section Name 和各个KEY 值的函数。本人通过C语言将其实现。函数的具体定义参考MSDN定义:https://msdn.microsoft.com/en-us/library/ms724353(VS.85).aspx程序具体功能部分摘录如下:ParameterslpAppName [in]The name of the section con
摘要由CSDN通过智能技术生成

这是一个能够读取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

C++
DWORD WINAPI GetPrivateProfileString(
  _In_   LPCTSTR lpAppName,
  _In_   LPCTSTR lpKeyName,
  _In_   LPCTSTR lpDefault,
  _Out_  LPTSTR lpReturnedString,
  _In_   DWORD nSize,
  _In_   LPCTSTR lpFileName
);


Parameters

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. 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.
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, "".

Avoid specifying a default string with trailing blank characters. The function inserts a null character in the lpReturnedStringbuffer to strip any trailing blanks.

lpReturnedString [out]

A pointer to the buffer that receives the retrieved string. 

nSize [in]

The size of the buffer pointed to by the lpReturnedString parameter, in characters.

lpFileName [in]
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值