An application must read the width and height values ​​from a file (.ini). When creating a window use these options. But, on startup, input.c opens and points to the line:

if ( integer64 ) *(__int64 UNALIGNED *)pointer = (unsigned __int64)num64; else if (longone) =====>*(long UNALIGNED *)pointer = (unsigned long)number;<===== else *(short UNALIGNED *)pointer = (unsigned short)number; 

As I understand it, the resulting value (8 bytes) exceeds the allowable (4 bytes).
There are two structures:

 struct ConfigStruct { int iSW, iSH; }ini; struct ConfigResult { int cSW, cSH; }res; 

In ConfigStruct, the values ​​obtained from the file are written. In ConfigResult, I wanted to write the int converted values.

This function reads the necessary values ​​from the file:

 int ConfigRW::ReadConfig(char* filename) { ifstream fcf; string line; fcf.open(filename,ios::in); while (!fcf.eof()) { getline(fcf,line); if(line.find("iScreenWidth = ")!=line.npos) { sscanf_s(line.c_str(),"iScreenWidth = %d",&ini.iSW); //Нужно преобразовать значение в int res.cSW = ini.iSW; } if(line.find("iScreenHeight = ")!=line.npos) { sscanf_s(line.c_str(),"iScreenHeight = %d",&ini.iSH); //Нужно преобразовать значение в int res.cSH = ini.iSH; } } fcf.close(); return 0; } 

In WinMain, assign values ​​from the ConfigResult structure to variables: ScreenWidth, ScreenHeight.

  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR lpCmdLine, int nCmdShow) { Config->ReadConfig("../Test/Settings.ini"); int ScreenWidth, ScreenHeight; ScreenWidth = Config->res.cSW; ScreenHeight = Config->res.cSH; //ScreenWidth = 1280; //ScreenHeight = 720; Prog->WinClass(hInstance); Prog->WinCreate(hInstance,"Test Application",ScreenWidth, ScreenHeight); Prog->WinLoop(msg); } 

Can you please tell me how to convert values ​​correctly?

  • GetPrivateProfileString () + atoi () try ... - Vladimir Martyanov
  • You seem to have a problem with type conversion. Tell me, how are pointer , num64 and number declared? - Harry

0