GetPrivateProfileInt-只读取默认值(GetPrivateProfileInt-

2019-09-16 15:47发布

我想读在C的.init配置文件++具有内容。

[IP地址]

IPADDRESS = 169.254.115.22

[ScanConfiguration]

Scanfrequency = 2500

ScanResolution = 2500

由startAngle = 700000

StopAngle = 1100000

到现在为止,我已经使用这个代码读取数据。 我的项目是Unicode字符集和字串值之前,因此,使用升。

 int iScanFreq =GetPrivateProfileInt(L"ScanConfiguration",L"Scanfrequency", 2500, L"filename.ini");
  int iScanRes =GetPrivateProfileInt(L"ScanConfiguration",L"ScanResolution", 2500, L"filename.ini");
  int iStartAngle =GetPrivateProfileInt(L"ScanConfiguration",L"StartAngle", -450000, L"filename.ini");
  int iStopAngle =GetPrivateProfileInt(L"ScanConfiguration",L"StopAngle", 2250000, L"filename.ini");

但我只得到了从文件中的变量值不正确的默认值。 我还没有对注册表的任何迹象。 有什么我在注册表中得到正确的价值做..

任何建议将是有益的感谢。

Answer 1:

一个想法浮现在脑海:GetPrivateProfileString和朋友都有点怪癖的与他们是如何找到INI文件。 除非你指定的INI文件的路径(甚至一些一样简单.\filename.ini ),他们认为该文件位于Windows目录。 这是几乎可以肯定不是你想要的,并可能导致无法找到该文件,从而为默认值。

另外,不要指望从这些功能完整的Unicode支持。 他们围绕ANSI文本只是Unicode的包装。



文章来源: GetPrivateProfileInt- reading only the default values