Calling functions from the dll and returning results - page 6

 
That f1-forum
Mike = Terranin = me :) And I've already given you the emulator on the Alpari forum. MTS doesn't interest me much, if you knew how many of them crashed on my emulator... :)
 
2 mike
:)) That's what I thought. If you're interested, you can see my system here
http://forum.alpari-idc.ru/viewtopic.php?t=45555
It's a bit of a mess, of course...
If you want, I'll describe the system, as you helped me with the emulator.
 
OK, if you want to share, then to murdoc (at) newmail.ru. I'll run it on my tester and let you know the results.
 
Renat:<br / translate="no"> By _default_ any import from a DLL is _completely_ forbidden_. This is the protection.
If you want to use external DLL, just enable "Confirm each DLL function call" button and see what is called there. This is also protection. As well as protection of all embedded file operations with access only to /history and /files directories.

If some person offers the Expert Advisor to the public with his DLL, the user either trusts this DLL or not. If he doesn't trust it, he won't download it. If he trusts it, he will have to tick the box "Allow import of DLL functions", otherwise the expert will not work. The names of the functions you are calling will also not be helpful to the Expert Advisor, because in order to know what a function does, you will have to disassemble the DLL, and not everyone will be able to do this. And in this DLL you can do a lot of nasty things, and the MT terminal can't prevent it. So "protection" is very relative and is not a real protection in this context. I think this is what mike meant.

The possibility of call of functions from user DLLs in MT 4 Expert Advisors is positioned as a replacement of API that is present in MT 3. So, all the same, there is an opportunity to transform MT 4 terminal into a datafeed and placing orders, which was one of the reasons (judging by various topics on the forums) why API was removed. But the API remained, it is very uncomfortable, many users talk about it, and it reminds of the situation from the joke: ".... I don't care, as long as you get bored". And this topic is a confirmation of that. The author hasn't received any specific and informative answers to his questions. These questions are also relevant to me, the answers are even more relevant :-).
Maybe I'm not an experienced programmer either, but in the current Expert Advisor<->DLL system, you, by definition, cannot have a simple and beautiful solution. To be more exact, within the scope of MQL4 there may be a beautiful solution, but within the scope of integration of MT4 terminal with custom software it is nothing, to put it mildly. There are other more functional solutions, you just need to find them :-). For example, we may create a DLL with functions like in mtapi.dll, but it will interact not with the server of dealing centre, but with the client terminal. In this case both the developer's interests will be preserved (without MT4 terminal the DLL will not be able to operate) and the people, that are able to create something more complex than MQL4 Expert Advisors, will have a good opportunity to integrate their own software (including their own gui) with the trading system. If such a variant has been considered and discussed, please give me a link (I have not come across such a variant). If not, I would like to know the opinion of the developers on this subject.

P.S. The "possibility of using the client API" line in the description of the trading terminal is very attractive. That's what attracted me to MetaTrader, and I was very disappointed with the lack of API in version 4 of the terminal. I hope, that the developers on the one hand, and API users on the other hand, will come to a compromise. The current state of affairs (calling DLL functions from ekperts) is unsatisfactory.
 
I ran into a problem, of course I may be too slow and I didn't get it right.....

I have a dll compiled for VC++
there's a function:

void __stdcall process_arr(double *in, double *out, int size);

in the Expert Advisor the following declaration:
#import "some.dll"
void process_arr(double in[], double& out[], int size);

arrays are declared next:

double arr1[100];
double arr2[100];

then I initialize the first array and pass both of them into the function
process_arr(arr1,arr2,100);

everything is passed, but the function refuses to return it

After returning from the function, I output the test value:
Print(arr2[1]);
and the following entry appears in the log
2005.09.19 18:30:03 arrtest EURUSD,H1: 2147483647
this is not the point, what does 2^31.... have to do with it?
it works the same way with any other element of the array.
although under the debugger before exiting the function the values in the out array are as they should be (close to the price - ~1.2)
 
The number 2147483647 is very close to zero, it seems.
2^31-1 to be exact, which should be like zero.
 
void __stdcall process_arr(double *in, double *out, int size); <br / translate="no">
Here is the declaration in the Expert Advisor:
#import "some.dll"
void process_arr(double in[], double& out[], int size);


Just a suggestion (because I am not familiar with MQL): is & really necessary for the second parameter?
void process_arr(double in[], double& out[], int size);
 
to Rosh, that's true, but we're talking about the double type, and there the number representation is "slightly" different, and 2^31 is quite far from 0.... :(

to VicK, the ampersand is the whole point, thanks to it I can actually change the contents of the array...
the second array is an array with return values
 
to VicK, the ampersand is the whole point, thanks to it I can actually change the contents of the array... <br / translate="no"> the second array is an array with return values


In this case there is no essence in the ampersand (I just tried it myself), and you can change the contents of the array thanks to something else :-). Did you look at the DLL example in the directory? Everything works fine there. Do it in the same way.
 
it looks like ampersand doesn't make any difference if we deal with array of double[] type
but everything works fine with int[]. I have a suspicion that here starts to smell bug.... :(
I would like to know developers' comments

if this thing came with source code, no one would bother, but... go ahead, I'm calling for help.
Reason: