封装供 mt5 使用的 dll ,有什么规范?有封装 class 成 dll 后被 mt5 访问的示例文档吗?

 

大家好:

我想封装一个 dll ,具体需求是:

一、业务需求:

1、想用 c++ 开发,使用 class 来封装应用;

2、目前 c++ 端已经开发好,并打包成功,但不能被 mt5 访问。 

二、当前问题:

1、mt5 端引用代码是:

#import "mytest\chanlun.h"

#import "mytest\mt5dll2.dll"

   IInterface *IF = IInterface::CreateInterface();

   int IF->Add(int a, int b);

#import

2、目前报错:

'IInterface' - unexpected token, probably type is missing?

三、主要代码:

1、完整代码,见附件;

2、头文件代码:

#ifdef MT5DLL2_EXPORTS
#define _CRT_SECURE_NO_WARNINGS
#define CHANLUN_API __declspec(dllexport)
#else
#define CHANLUN_API __declspec(dllimport)
#endif

class CHANLUN_API IInterface
{
public:
    IInterface();
    ~IInterface();
    static IInterface* CreateInterface();
    virtual void Init() = 0;                // 纯虚函数意味着这个类是一个抽象类,不能直接创建该类的对象,而必须由派生类实现这些虚函数
    virtual void Destroy() = 0;
    virtual char* GetName() = 0;
    virtual int Add(int a, int b)=0;
private:
};

3、程序体代码:

#include "pch.h"
#include "chanlun.h"
#include <iostream>


class  FHello : public IInterface
{
public:
    FHello();
    ~FHello();
    virtual void Init();
    virtual void Destroy();
    virtual char* GetName();
    virtual int Add(int a, int b);
private:
    int aa;
    char Name[1024];
};
FHello::FHello() {
    memset(Name, 0, 1024);
    //strcpy(Name, "Hello");
}
FHello::~FHello() {
}
void FHello::Init() {
    printf("FHello::Init() \n");
}
void FHello::Destroy() {
    printf("FHello::Destroy() \n");
}
int FHello::Add(int a, int b) {
    aa = a + b;
    return aa;
}

char* FHello::GetName() {
    return Name;
};
IInterface* IInterface::CreateInterface() {
    return new FHello();
};

IInterface::IInterface() {        // 构造函数,可以没有实际内容,但不能没有
};


IInterface::~IInterface() {        // 析构函数,可以没有实际内容,但不能没有
};


4、mt5 调用代码:

#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window

#import "mytest\chanlun.h"
#import "mytest\mt5dll2.dll"
   IInterface *IF = IInterface::CreateInterface();
   int IF->Add(int a, int b);
#import


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
  if(rates_total != prev_calculated){
   //int c = TestAdd(300, 200);
   int c = IF->Add(10, 30); 
   printf("dll 调用结果:%d", c);
  }
   
   return(rates_total);
  }
附加的文件:
mt5dll2.zip  3 kb
 
在 Linux 上利用 C++ 多线程支持开发 MetaTrader 5 概念验证 DLL
在 Linux 上利用 C++ 多线程支持开发 MetaTrader 5 概念验证 DLL
  • www.mql5.com
我们将开始探索如何仅基于 Linux 系统开发 MetaTrader 5 平台的步骤和工作流程,其中最终产品能在 Windows 和 Linux 系统上无缝运行。 我们将了解 Wine 和 Mingw;两者都是制作跨平台开发任务的基本工具。 特别是 Mingw 的线程实现(POSIX 和 Win32),我们在选择追随哪一个时需要仔细考虑。 然后,我们构建一个能在 MQL5 代码中所用的概念验证 DLL,最后比较两种线程实现的性能。 这一切都是为了您的基金能进一步扩张自己。 阅读本文后,您应该可以轻松地在 Linux 上构建 MT 相关工具。
 
楼主,有机会可以互相交流。