GetPrivateProfileStringA strange behaviour

 
I have a great EA only to be let down by the strange behavoir of the kernell function:
GetPrivateProfileStringA

here is what is happening exactly documented here: https://www.mql5.com/en/forum/56876

in the code below: when the function is called for the second time: the line 1.Returned String= contains a value from the previous call its strange... anyone with a suggestion all i want is to read an ini file.

string ReadIniString(string FileName, string SectionName, string KeyName, 
                     string Default = "")
  {
   string ReturnedString ="";
   Print("1.Returned String=",ReturnedString);                                       
   int nValue = GetPrivateProfileStringA(SectionName, KeyName, Default, 
                                         ReturnedString, 255, FileName);
   Print("2.Returned String=",ReturnedString);                                       
   if(nValue > 0){
       return(ReturnedString);
   }
   else {
     Print("Failed to read File[",FileName,"] Section[",SectionName,"] Key[",KeyName,"] Returning Default Value[",Default,"]");
       return(Default);
   }    
  }

 
tinashe: anyone with a suggestion
string ReturnedString ="";
int nValue = GetPrivateProfileStringA(SectionName, KeyName, Default, 
                                      ReturnedString, 255, FileName);
Per File Operations via WinAPI - MQL4 Articles I suggest you make sure ReturnedString is at least 255 characters long, before calling GPPS
 

Well i just tried to make sure the size of the string is 255 all spaces and the return value is blank. it returns only the 255 spaces. but the return value nValue if greater than 0.

Any other easy solution i can use, i never thought it will be this hard to read an ini file

 
Well I managed to make it work, all i needed to do was make sure the initial value of the string is "x   "; x followed by lots of spaces, spacess alone it doesn't work. eish very strange indeed.
Reason: