MQL5 如何从 dll 文件导入类函数?

问题描述

我想弄清楚如何为 mt5 编写 dll,并为 C++ 编写了一个简单的 dll。

dllmain.cpp

// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "Header1.h"

int iParam;

BOOL APIENTRY DllMain( HMODULE hModule,DWORD  ul_reason_for_call,LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        iParam = 7;
        break;
    case DLL_THREAD_ATTACH:
        iParam += 1;
        break;
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

const int GetSomeparam() {
    return iParam;
}

Project2.cpp

// Project2.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"
#include "Project2.h"
#include "Header1.h"

PROJECT2_API int printing_f() {
    return 1000;
}

PROJECT2_API int xyz::printing_class() {
    return 2000;
}

Project2.h

// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the PROJECT2_EXPORTS
// symbol defined on the command line. This symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// PROJECT2_API functions as being imported from a DLL,whereas this DLL sees symbols
// defined with this macro as being exported.
#ifdef PROJECT2_EXPORTS
#define PROJECT2_API /*extern "C"*/ __declspec(dllexport)
#else
#define PROJECT2_API __declspec(dllimport)
#endif
PROJECT2_API void printing_f(char* pChar);

class xyz
{
private:
    int abc;
public:
    PROJECT2_API int printing_class();
};

其实这里一切都很简单,有一个简单的函数printing_f——它是一个简单的导入函数,还有一个我想从printing_class dll中调用的类方法

在 mql5 中,我尝试这样称呼它们

#import "Project2.dll"
int printing_f();
int printing_class();
#import



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {

   printing_f();
   printing_class();
  }
//+------------------------------------------------------------------+

一个函数调用成功,但是调用第二个函数出错

在“Project2.dll”未解析的导入中找不到“printing_class” 函数调用

实际上,我如何从 MQL5 中的类调用函数

PS:如果我用 C++ 编写一个应用程序,一个访问printing_class 函数的exe 文件,那么一切顺利,它在mql5 中不起作用

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)