Dear all,
I have problem with reading from ini file. My code is as follows, but it has Error with GetPrivateProfileInt. It cannot read and the error is :


error C2664: 'GetPrivateProfileIntW' : cannot convert parameter 1 from 'const char [9]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Please Help

--------------code-------------

void ReadIniFile(const char* inifile)
{
printf("Reading: %s\n", inifile);
char entry[128];
res=GetPrivateProfileInt("settings", "resolution", 256, inifile); /* resolusi paparan */
hres=res/2;
GetPrivateProfileString("settings", "brightness", "2.5", entry, 128, inifile);
brightness=atof(entry);
step=GetPrivateProfileInt("settings", "step", 2, inifile); /* untuk jeda masa bagi rendering */
GetPrivateProfileString("settings", "near", "0.1", entry, 128, inifile); /* ketipan viewplane */
near_plane=atof(entry);
GetPrivateProfileString("settings", "far", "40.0", entry, 128, inifile);
far_plane=atof(entry);
double angle=GetPrivateProfileInt("settings", "smooth_angle", 2, inifile); /* sudut pengujian bagi normal segitiga */
cos_angle=cos(angle * 3.1415927 / 180.0); /* darjah->radian */
GetPrivateProfileString("settings", "stop_at", "0.0001", entry, 128, inifile);
converged=atof(entry);/* nilai penumpuan */

error C2664: 'GetPrivateProfileIntW' : cannot convert parameter 1 from 'const char [9]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

You are passing a character array to a LPCWSTR which is a double byte character array. You will have to either undo your UNICODE define which is not recommended or convert the const char[9] to a wchar_t based type.

Member Avatar for MonsieurPointer

You will have to either undo your UNICODE define which is not recommended

If you are using Visual Studio, then it is a matter of changing project settings. You can also force the use of the ANSII version by explicitly calling GetPrivateProfileIntA instead.

If you are using Visual Studio, then it is a matter of changing project settings

I have a similar problem and am using Visual studio. It would really help if you could elaborate. My program works fine in debug mode but in release mode it complains about skipped header files when the compiler looked for pre-compiled headers

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.