Hi Igor, This does not work. I use Win7 Professional (64 bit). There is message "uninit reason 0" but no file recorded.
Here is sample script that I run, but no luck to generate "MyFirst.ini" file.
//+------------------------------------------------------------------+ //| ReadwriteIni_sample.mq4 | //| Copyright 2019, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2019, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict #include <IniFiles.mqh> //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { string theFile = "C:\\MetaTrader4\\_temp_02\\tester\\MyFirst.ini"; WriteIniString( theFile , "FirstSection" , "VarValue" , "HelloWorld" ); Print("*** From the INI attempt ***"); } //+------------------------------------------------------------------+
https://docs.mql4.com/files/fileopen:
"For security reasons, work with files is strictly controlled in the MQL4 language. Files with which file operations are conducted using MQL4 means, cannot be outside the file sandbox."
Try it with a local filename (theFile = "MyFirst.ini") and check in the Files folder if it appears there. (<MT4 installation folder>\MQL4\Files)
- docs.mql4.com
https://docs.mql4.com/files/fileopen:
"For security reasons, work with files is strictly controlled in the MQL4 language. Files with which file operations are conducted using MQL4 means, cannot be outside the file sandbox."
Try it with a local filename (theFile = "MyFirst.ini") and check in the Files folder if it appears there. (<MT4
installation folder>\MQL4\Files)
I can confirm that this is not working on my instance too,
Windows 10 x64,
WriteIniBool("MyticalBot.ini", "BOT", "OnOFF", botIsOn); WriteIniDouble("MyticalBot.ini", "BOT", "Lots", lotSize);
As you can see, i'm trying to write local, but no file shows up at all.
The method calling windows api modified.
#property library
#import
These codes can work normally:
string ReadIniString(string FileName, string SectionName, string KeyName,
string Default = "")
{
string ReturnedString;
StringInit(ReturnedString,1024, 0);
char sname[1024], kname[1024], defchar[1024], retchar[1024], fname[1024];
StringToCharArray( FileName, fname);
StringToCharArray( SectionName, sname);
StringToCharArray( KeyName, kname);
StringToCharArray( Default, defchar);
StringToCharArray( ReturnedString, retchar);
int nValue = GetPrivateProfileStringA(sname, kname, defchar,
retchar, 1024, fname);
if(nValue > 0)
{
ReturnedString=CharArrayToString(retchar);
return(ReturnedString);
}
else
return(Default);
}
The method calling windows api modified.
#property library
#import
These codes can work normally:
string ReadIniString(string FileName, string SectionName, string KeyName,
string Default = "")
{
string ReturnedString;
StringInit(ReturnedString,1024, 0);
char sname[1024], kname[1024], defchar[1024], retchar[1024], fname[1024];
StringToCharArray( FileName, fname);
StringToCharArray( SectionName, sname);
StringToCharArray( KeyName, kname);
StringToCharArray( Default, defchar);
StringToCharArray( ReturnedString, retchar);
int nValue = GetPrivateProfileStringA(sname, kname, defchar,
retchar, 1024, fname);
if(nValue > 0)
{
ReturnedString=CharArrayToString(retchar);
return(ReturnedString);
}
else
return(Default);
}
This is still not compiling in metatrader 5, can you provide the full code that would compile in mt5 please? thanks
It doesn't work i put this ini file in MQL4/Files folder as you can see in this image:
and write this code in a script:
#include <IniFiles.mqh> //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- double test; test=ReadIniDouble("test.ini","Section","test"); Comment(test); }
and compile it without any error but output is: 0.0
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Library of functions for working with INI-files.:
Author: Igor Kim