GetPrivateProfileStringW in MQL4 bytes read is just 1.

 
  string Section="Trading";
  string Key = "Slippage";
  string DefaultValue="NotFound!";
  string FileName = "c:\\Temp\\Trading\\settings.ini";
  ushort buffer[4096];
  uint read = GetPrivateProfileStringW(Section, Key, DefaultValue, buffer, ArraySize(buffer), FileName);
  string str_res = ShortArrayToString(buffer);
  Print("Output=",str_res, ", Bytes Read=",read);

The above code is producing undesirable output:

Output=3, Bytes Read=1

the declaration is as follows:

#import "kernel32.dll"
   uint WritePrivateProfileStringW(string &lpAppName, string &lpKeyName, string &lpString, string &lpFileName);
   uint GetPrivateProfileStringW(string &lpAppName, string &lpKeyName, string &lpDefault, ushort &lpReturnedString[], uint nSize, string &lpFileName);   
#import

How do i use this function properly GetPrivateProfileStringW anyone to help?

 

are you aware ?

Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should store initialization information in the registry.

 
#import "kernel32.dll"
   bool WritePrivateProfileStringW(string lpSectionName, string lpKeyName, string lpString, string lpFileName);
   int  GetPrivateProfileStringW(string lpApplicationName, string lpKeyName, string lpDefault, string lpReturnedString, int nSize, string lpFileName);
#import

i would prefer to use

int GetPrivateProfileSectionW(string lpAppName, string lpReturnedString, int nSize, string lpFileName);

or maybe

int GetPrivateProfileSectionW(string lpAppName, char& lpReturnedString[], int nSize, string lpFileName);
 

Well I tried this function all I get is the first entry of the section, other entries are not returned.

If i have a file name with entries:

[Trading]

Lots=0.1

Slippage=3

I only get Lots=0.1

 

because you have to deal with a terminator

   for(int x = 0; x <= ArraySize(buffer); x++)
      {
      if (buffer[x] == 0)
         {
         buffer[x] = '\n';
         }
      }
   for(int y = 0; y <= ArraySize(buffer); y++)
      {
      if (buffer[y] == '\n' && buffer[y+1] != '\n')
         {
         for(int z = y; z <= ArraySize(buffer) - y; z++)
            {
            buffer[z] = buffer[z+1];
            }
         }
      }
  string str_res = CharArrayToString(buffer);
  Print("Output=",str_res, ", Bytes Read=",read);