Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetPrivateProfileInt- reading only the default values

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.

like image 829
ShivShambo Avatar asked Apr 20 '12 02:04

ShivShambo


1 Answers

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.

like image 168
ChrisV Avatar answered Sep 27 '22 22:09

ChrisV