GetPrivateProfileInt-仅读取默认值 [英] GetPrivateProfileInt- reading only the default values

查看:805
本文介绍了GetPrivateProfileInt-仅读取默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用c ++读取具有内容的.init配置文件.

I am trying to read a .init config file in c++ having the content.

[ipaddress]

[Ipaddress]

Ipaddress = 169.254.115.22

Ipaddress=169.254.115.22

[ScanConfiguration]

[ScanConfiguration]

Scanfrequency = 2500

Scanfrequency=2500

ScanResolution = 2500

ScanResolution=2500

StartAngle = 700000

StartAngle=700000

StopAngle = 1100000

StopAngle=1100000

直到现在,我已使用此代码读取数据.我的项目是Unicode字符集,因此在字符串值前使用L.

Till Now, I have used this code for reading the data. My project is of Unicode character set and hence used L before the string values.

 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");

但是我仅从文件中获取变量中的默认值,而不是正确值.我尚未对注册表进行任何操作.我需要在注册表中做些什么来获取正确的值.

But I am getting only the default values in the variables not the correct values from the file. I have not done anything with the registry yet. Is there anything I have to do in registry for getting the correct value..

任何建议都会有所帮助 谢谢.

Any suggestions will be helpful Thanks.

推荐答案

想到一个主意:GetPrivateProfileString和朋友在查找INI文件的方式上有些古怪.除非您指定INI文件的路径(甚至是简单的.\filename.ini),否则它们会假定该文件位于Windows目录中.几乎可以肯定这不是您想要的,并且可能会导致找不到文件,从而导致默认值.

One idea comes to mind: GetPrivateProfileString and friends have a bit of a quirk with how they find the INI file. Unless you specify a path to the INI file (even something as simple as .\filename.ini), they assume the file is located in the Windows directory. This is almost certainly not what you want, and will probably lead to not finding the file, and thus to default values.

此外,不要期望这些功能完全支持Unicode. 它们只是围绕ANSI文本的Unicode包装.

Also, don't expect full Unicode support from those functions. They're just Unicode wrappers around ANSI text.

这篇关于GetPrivateProfileInt-仅读取默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆