GetPrivateProfileInt函数使用

  GetPrivateProfileInt函数目的是读取配置文件,赋值参数。

官网给出的信息

UINT GetPrivateProfileInt(
  LPCTSTR lpAppName,
  LPCTSTR lpKeyName,
  INT     nDefault,
  LPCTSTR lpFileName
);

Parameters

参数名说明
lpAppNameThe name of the section in the initialization file.
lpKeyNameThe name of the key whose value is to be retrieved. This value is in the form of a string; the GetPrivateProfileInt function converts the string into an integer and returns the integer.(也就是说这个值本身是按照string来存储的,GetPrivateProfileInt 函数将该string转换为整数,注意是整数,也就是说说该函数不能用来赋值double或float等小数)
nDefaultThe default value to return if the key name cannot be found in the initialization file.
lpFileNameThe 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 ValueThe return value is the integer equivalent of the string following the specified key name in the specified initialization file. If the key is not found, the return value is the specified default value.

其他帮助理解的信息

  The function searches the file for a key that matches the name specified by the lpKeyName parameter under the section name specified by the lpAppName parameter. A section in the initialization file must have the following form:

[section]
key=value
      .
      .
      .

也就是说,当进入到 lpFileName指定的ini文件后,先找到[section]片段,再在该片段下找到lpKeyName变量,将其值赋给返回值,如果没有在指定路径下找到lpFileName的ini文件,就将nDefault默认值赋给返回值。


引申

配置文件中经常用到ini文件,在VC中其函数分别为:

操作函数
写入.ini文件bool WritePrivateProfileString (LPCTSTR lpAppName,LPCTSTR lpKeyName,LPCTSTR lpString,LPCTSTR lpFileName);
读取.ini文件DWORD GetPrivateProfileString(LPCTSTR lpAppName,LPCTSTR lpKeyName,LPCTSTR lpDefaut,LPSTR lpReturnedString,DWORD nSize,LPCTSTR lpFileName);
读取整形值UINT GetPrivateProfileInt(LPCTSTR lpAppName,LPCTSTR lpKeyName,INT nDefault,LPCTSTR lpFileName);

  GetPrivateProfileInt和GetPrivateProfileIntA两个函数的差别我没有发现,按照微软官方的解释,没看到差别,如果有人知道,望指出,感激不尽。
GetPrivateProfileInt
GetPrivateProfileIntA
  既然GetPrivateProfileInt函数是用来赋值整数的,那么如果需要配置的参数是double或float等小数,该用什么函数?

参考来源

  本文参考来源为如下链接。
https://docs.microsoft.com/zh-cn/windows/win32/api/winbase/nf-winbase-getprivateprofileint?redirectedfrom=MSDN

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值