我试图在MQL4中编写一个简单的程序,该程序通过引用将变量传递给C++ DLL函数,并在MQL4中打印更新的变量值。下面给出的是我的代码。
DLL功能:
void Test(int* X)
{
*X = 6;
}
MQL4代码
#import "Test.dll"
void Test(int&);
#import
void OnStart()
{
int A;
Test(A);
Alert(A);
}
但是我没有从C++函数中获取变量A的任何值(value)。有人可以帮助我在这里做错什么吗?
提前致谢
最佳答案
让我们从DLL端开始:
int TestMoreApproachesAtONCE( int *X,
int *Y,
int Z
)
{
*X = 6; // 6 assigned to a 4B-memory chunk ref'd by *X
Y = 6; // 6 assigned to a variable Y
return( Z ); // Z returned as a value passed from Caller
}
MQL4要求DLL具有:
现在演示MQL4端:
#import "Test.dll" // -----------------------------------------------
void Test( int& );
int TestMoreApproachesAtONCE( int &X,
int &Y,
int Z
);
#import // "Test.dll" // -----------------------------------------------
void OnStart()
{
int A = EMPTY,
B = EMPTY,
C = EMPTY;
// ---------------------------------------------------<PRE>
Print( " TEST:: inital values are: A = ", A,
" B = ", B,
" C = ", C
);
// ---------------------------------------------------<TEST>
C = TestMoreApproachesAtONCE( A, B, 6 );
// ---------------------------------------------------<POST>
Print( " TEST:: final values are: A = ", A,
" B = ", B,
" C = ", C
);
}
Anyway, enjoy the Wild Worlds of MQL4 -- Also may enjoy to click and read other posts on issues in MQL4/DLL integration and/or signalling/messaging in MQL4 domains. Feel free to ask more
最后,MQL4文档指出:
关于c++ - 如何通过引用将参数从MQL4传递给C++ DLL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39520941/