referencing and dereferencing c++

 

Hi All,

ok this is a bit off topic, but I know there are some good C(++) coders around on this forum. So i'll will give it a try any way.


here the problem I'm having... Im importing a dll in MT with follow function in it.


#import "some.dll"
int MB_GetInputActRange(int idx, double& pActMin, double& pActMax);


in the c++ wrapper I have this function


MT4_EXPFUNC int __stdcall MB_GetInputActRange(_MB_INT idx, double& pActMina, double& pActMaxa){//, double* pActMin, double* pActMax
    
    //double* pActMin = &pActMina;
    //double* pActMax = &pActMaxa;
 
    double pActMin = 0;
    double pActMax = 0;
    int iReturn = _MB_GetInputActRange(idx, &pActMin, &pActMax);
    char my_string[26];
    sprintf(my_string,"test %18.6f",pActMax);
    pActMaxa = pActMax;
    MessageBox(NULL,my_string,"Application Message", MB_OK | MB_ICONINFORMATION);
    return(iReturn);
//    return(_MB_GetInputActRange(idx, pActMin, pActMax));
}



this is calling _MB_GetInputRange


EMBRetVal __declspec(dllimport) __stdcall _MB_GetInputActRange(_MB_INT idx, double* pActMin,
                                                               double* pActMax);

now the problem is in every way I reference / dereference MT will crash when trying to access the function.

It must be a simple problem... but I'm missing some of the basics of C++ while still learning


Is there enough info to work with?


thanks,


Russell

 

I also tryed this


MT4_EXPFUNC int __stdcall MB_GetInputActRange(_MB_INT idx, double* pActMina, double* pActMaxa){//, double* pActMin, double* pActMax
    


    int iReturn = _MB_GetInputActRange(idx, &*pActMina, &*pActMaxa);
    char my_string[26];
    sprintf(my_string,"test %18.6f",pActMax);
//    pActMaxa = pActMax;
    MessageBox(NULL,my_string,"Application Message", MB_OK | MB_ICONINFORMATION);
    return(iReturn);
//    return(_MB_GetInputActRange(idx, pActMin, pActMax));
}


in MT the referenced values return 0

 

Problem solved


MT4_EXPFUNC int __stdcall MB_GetInputActRange(_MB_INT idx, double* pAct){
    
    int iReturn = _MB_GetInputActRange(idx, &pAct[0], &pAct[1]);
    char my_string[26];
    sprintf(my_string,"test %18.6f",pAct[1]);
    MessageBox(NULL,my_string,"Application Message", MB_OK | MB_ICONINFORMATION);
    return(iReturn);
}
 

Russel, I came across your thread when you commented on my thread at 'EA that makes an internet request'

I don't know c++ at all and am new to MT4 as well but... is it easy to call c++ from MT4? If so, this may help my situation. From your example above, I gather that it may as easy as making a dll in c++ and them importing it into MT4. Then you can call the c++ funtion at anytime?

Reason: