DxdCn wrote >>
[...] only use array to return multi variables.
This is conclusion !!!
who have other opinion?
AFAIK you're correct that MT4 crashes/doesn't work if you try passing it a non-array variable by reference, and then set the value of that variable in a DLL using a pointer. You have to use arrays instead.
For example, with the following DLL...
extern "C" int WINAPI TestDll(int * p)
{
*p *= 2;
return *p;
}
... the following MQL script causes a fatal crash (in build 220):
#import "TestDll.dll"
int TestDll(int & Param);
#import
int start()
{
int TestVar = 2;
int Result = TestDll(TestVar);
MessageBox("Result: " + Result + "\r\nValue of TestVar: " + TestVar);
}
However, the same DLL works fine if you declare the MQL stuff as follows, turning TestVar into a 1-item array rather than a plain integer:
#import "TestDll.dll"
int TestDll(int & Param[]); // The parameter is now an array - see below
#import
int start()
{
int TestVar[1] = {2}; // Declare TestVar as an array with 1 slot, and put the value 2 into it
int Result = TestDll(TestVar);
MessageBox("Result: " + Result + "\r\nValue of TestVar: " + TestVar[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
In DLL,
MT4_EXPFUNC char*__stdcall GetState(int& st,char* which,int& prd)
in such function, MT dead if let st= 123;
MT4_EXPFUNC char*__stdcall GetState(int* st,char* which,int* prd)
in such function, MT no dead.
Both do not change parameters st, which, prd.
only can return soththing with return(.....);
only use array to return multi variables.
This is conclusion !!!
who have other opinion?