Importing a C++ class to MQL5

 

Hello everyone !

Can someone tell me how to include C++ classes with .DLL

My code is not working:


MQL5LAZY

#import "MQL5DLLSamples.dll"

void CreatingLazy(int ordre,float raison,float THRESHOLD1,float THRESHOLD2,int K_MIN,int K_MAX,float& present[],int size);
void Communicate();
#import

void OnStart()
  {
   float present[8];
   CreatingLazy(8,0.85,0,0,3,9,present,ArraySize(present));

    float x=Communicate();

  }


LAZYPREDICTOR.CPP

#include "stdafx.h"
#include "LazyPredictor.h"
using namespace std;

LazyPredictor::LazyPredictor(int ordre,float raisonarg,float thresholdbuy,float thresholds,int kminarg,int kmaxarg,string File)
{
     test=4

}

LAZYPREDICTOR.H


class _DLLAPI LazyPredictor
{
public:

    LazyPredictor(int,float,float,float,int,int,std::string);

    float test;

};

MQL5DLLSamples.CPP

#include "stdafx.h"
#include "LazyPredictor.h"
using namespace std;
LazyPredictor* MonLazy;
_DLLAPI void __stdcall CreatingLazy(int ordre,float raison,float THRESHOLD1,float THRESHOLD2,int K_MIN,int K_MAX,float* present,int size)
{
    MonLazy=new LazyPredictor(8,0.85,0,0,3,9,"filetext.txt");

}

_DLLAPI float Communicate()
{

    return MonLazy->test;

}


The error is the following in MQL5 Terminal : Access violation read to 0x0000000000000028 in 'C:\Program Files\MetaTrader 5\MQL5\Libraries\MQL5DLLSamples.dll'

Is my LazyPredictor constructor called ? What is the optimal way to call C++ classes with MQL5 ?

Thanks in advance,

 

Could you write to ServiceDesk?

Please attach sources and compiled DLL's into your ticket. 

Get in touch with developers using Service Desk!
  • www.mql5.com
We therefore attach great importance to all user reports about issues in our programs and try to answer each one of them.