Download MetaTrader 5
To add comments, please log in or register
All MQL5.community events are grouped together. Have a look at the Wall!
Tinashe Chipomho
248
Tinashe Chipomho 2014.03.26 02:59 
  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?

qjol
3243
qjol 2014.03.26 03:08  

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.

qjol
3243
qjol 2014.03.26 03:26  
#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);
Tinashe Chipomho
248
Tinashe Chipomho 2014.03.26 06:05  

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

qjol
3243
qjol 2014.03.26 13:36  

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);
/
To add comments, please log in or register