1

我写了这个简单.DLLC#

namespace mcMath
 {
     public class Class1
     {
        public static double addUp(double num1, double num2)
         {
             return (num1 + num2);
         }

    }
 }

当我尝试#import将此.DLL文件转换为MetaTrader4平台MQL4代码时,出现错误:

Cannot load 'mcMath.dll' [126].

    10:55:17.373    Expert fadi EURUSD,H4: loaded successfully
0   10:55:17.689    Expert fadi EURUSD#,H1: loaded successfully
3   10:55:19.224    Cannot load 'mcMath.dll' [126]
0   10:55:19.225    fadi EURUSD,H4: initialized
3   10:55:24.027    Cannot load 'mcMath.dll' [126]
0   10:55:24.028    fadi EURUSD#,H1: initialized
1   10:55:27.463    Cannot call 'mcMath.dll::addUp', 'mcMath.dll' is not loded    
1   10:55:27.494    fadi EURUSD#,H1: unresolved import function call
0   10:55:27.522    fadi EURUSD#,H1: uninit reason 4
0   10:55:27.538    Expert fadi EURUSD#,H1: removed

我允许DLL在平台选项中导入。

Q1:有人有同样的问题吗?
Q2:如何解决?

MQL4代码:

   #import "mcMath.dll"
   double addUp(double number1,double number2);
   #import
   double number1, number2;
   int OnInit()
   {
  //---
      number1=10.5;
      number2=20.3;
      double number3= addUp(number1,number2);
      Print("the result is: " + number3);
   //---
   return(INIT_SUCCEEDED);
    }
4

1 回答 1

0

A1:不,这个问题没有任何通用的答案。

A2:让我们创建一个必须满足的项目清单,以便#import从 DLL:

  1. MetaTrader4 终端允许从 DLL 使用(导入)... PASS
  2. 所述DLL文件的位置...待定
  3. DLL 导出函数的调用签名匹配...待定

为了 [2],请始终检查您是否已将包含您选择的 DLL 的文件放置到文件<TerminalDir>/MQL4/Libraries夹中。

为了隔离 [3],请始终使用简单的、无参数的集成测试函数并int test_DLL_LOADED(){ return( 1 ); }MQL4代码中验证正确的返回值:

#import "<aDllFileNAME>"                       // MQL4 pre-processor directive
                        int test_DLL_LOADED(); // DLL  parameter-less signature
                         ...                   //      other signatures of import'd f()
#import                                        // MQL4 pre-processor directive


int OnInit(){
    if ( !test_DLL_LOADED() ){
       // FAILED:                              // CLOSE ALL FILE-IOs
                                               // SEND SIGs / MESSAGEs TO PEERs
                                               // UPDATE GLOBAL VARIABLEs
                                               // LOG EVENT
                                               // GET READY FOR A GRACEFUL EXIT
          ...
       // EXIT:
          ExpertRemove();
    }
 // PASSED: PROCEED WITH A NEXT INTENDED SETUP STEP
    ...

}
于 2016-07-14T14:59:06.603 回答