GetPrivateProfileInt- reading only the default values

别等时光非礼了梦想. 提交于 2019-12-14 03:45:40

问题


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

[Ipaddress]

Ipaddress=169.254.115.22

[ScanConfiguration]

Scanfrequency=2500

ScanResolution=2500

StartAngle=700000

StopAngle=1100000

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.


回答1:


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.

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



来源:https://stackoverflow.com/questions/10239576/getprivateprofileint-reading-only-the-default-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!