New article at mql5.com - How to Exchange Data: A DLL for MQL5 in 10 Minutes

 

New article How to Exchange Data: A DLL for MQL5 in 10 Minutes is published at mql5.com:

Now not so many developers remember how to write a simple DLL, and what are special features of different system binding. Using several examples, I will try to show the entire process of the simple DLL's creation in 10 minutes, as well as to discuss some technical details of our binding implementation. I will show the step-by-step process of DLL creation in Visual Studio with examples of exchanging different types of variables (numbers, arrays, strings, etc.). Besides I will explain how to protect your client terminal from crashes in custom DLLs.

Author: Renat Fatkhullin

 

Good article, but it raises some big concerns.

5. DLL calls wrapper and loss of speed on calls

As already described above, every call of DLL functions is wrapped into a special wrapper in order to ensure safety. 
This binding masks the basic code, replaces the stack, supports stdcall / cdecl agreements and monitors exceptions within the functions called.

This work inevitably leads to delay of the calling function. 
Therefore, it isn't recommended to perform very frequent DLL function calls (hundreds or thousands of times per second) for small operations. 

It's better to make infrequent calls.

I am all for adding protection for the application but not at the expense of performance. This is another change from MT4 as exceptions in dlls cause MT4 to crash, but well written code should handle this scenario, I would much rather see articles on writing safe code in dll's to overcome these sorts of problems. So now due to bad coding habits everyone has to pay a performance cost.

This is very very bad if you have libraries of algorithms that are called on a tick bases, I would dare say render them useless. Given alot of the feedback I have seen re MT5 isn't good mostly due to people needing to rewrite indicators etc. this is just another item that causes alot of frustration, and seeing as it does impact performance I would imagine others like myself that user extensive use of DLL's will just stay with MT4 for as long as posible and look for another platform where this isn't a problem.

Why oh why could Metaquotes just not add a slightly different method for invoking dll's in a safe way. The developer could then choose to load via safe loading or performance loading and ensure they write good code that catches exceptions.

"It's better to make infrequent calls" I mean seriously what sort of statement is that

 

There's no amount of computing power that a chip designer can possibly create that a programmer cannot figure out how to waste.

Renat, thanks for a well written and informative article on an important subject.

chipdude

 
pfx:this is just another item that causes alot of frustration

Indeed. It is really sad to see how Metaquotes with deadly accuracy always finds the wrongest possible solution to every non-problem that arises from their hallucinations (in this case the non problem of segfaults in dlls that deserve to segfault)


The only shortcoming of MQL4 that ever existed in real world scenarios was the absence of function pointers that would enable us to implement late binding features in mql and that could be passed to DLLs to let us implement callbacks, and although Metaquotes now managed to completely mess up mql4 for no reason into something new called mql5 with slightly extended syntax but no additional features and just made everything a bit worse than it was before, they still failed to solve the only real problem that has ever existed.


It's really sad having to watch all this screaming incompetence leading to more and more bizarre results without being able to do anything about it.

 
7bit:

Indeed. It is really sad to see how Metaquotes with deadly accuracy always finds the wrongest possible solution to every non-problem that arises from their hallucinations (in this case the non problem of segfaults in dlls that deserve to segfault)


The only shortcoming of MQL4 that ever existed in real world scenarios was the absence of function pointers that would enable us to implement late binding features in mql and that could be passed to DLLs to let us implement callbacks, and although Metaquotes now managed to completely mess up mql4 for no reason into something new called mql5 with slightly extended syntax but no additional features and just made everything a bit worse than it was before, they still failed to solve the only real problem that has ever existed.


It's really sad having to watch all this screaming incompetence leading to more and more bizarre results without being able to do anything about it.

Well said, function pointers now that would have been an awesome feature. I still quite figure out why you would provide a extensive development environment only to restrict it by so much. Mql3 had an api, Mql4-5 are black boxes. It would be nice if we had the ability to raise events instead of having to wait for tick data.

 

I think it all comes down to MQ being a business. It's a business decision to have a 'no pointer' simplified semi c/c++ like language on their own IDE (with their own compiler). Let's think of the alternative - the API approach, where MQL4 could have been a C API and MQL5 could have been a C++ API. MQ wouldn't need to develop their own IDE and there would be no point anyway cause the majority of programmers would use others. But the result, I suspect, would be that the programming community for MetaTrader would have been a fraction of what it is today. Only professional programmers would be drawn to that.


I think that by simplifying the language and placing it in their own IDE they 'took control' over the platform's potential programming community and made it what it is today. For comparison, the majority of big brokers have various API's that allow u to connect to their platform. But it's virtually impossible for any non-professional programmer to attempt doing that. All these API's are highly complex, have no back-testing functionality (so verification can only be done on Demo's), have very technical documentation and virtually no community-based support. The result it is that only institutional clients (with professional programmers) use them.


Anyway, that's all IMHO. Personally, I wish MQL was just a C++ API. But then again, I am sure it would not be the success it is today if that was so.


pfx wrote >>

It would be nice if we had the ability to raise events instead of having to wait for tick data.

FYI, MQL5 is event driven, no need to wait for ticks.

 
gordon:

I think it all comes down to MQ being a business. It's a business decision to have a 'no pointer' simplified semi c/c++ like language on their own IDE (with their own compiler). Let's think of the alternative - the API approach, where MQL4 could have been a C API and MQL5 could have been a C++ API. MQ wouldn't need to develop their own IDE and there would be no point anyway cause the majority of programmers would use others. But the result, I suspect, would be that the programming community for MetaTrader would have been a fraction of what it is today. Only professional programmers would be drawn to that.


I think that by simplifying the language and placing it in their own IDE they 'took control' over the platform's potential programming community and made it what it is today. For comparison, the majority of big brokers have various API's that allow u to connect to their platform. But it's virtually impossible for any non-professional programmer to attempt doing that. All these API's are highly complex, have no back-testing functionality (so verification can only be done on Demo's), have very technical documentation and virtually no community-based support. The result it is that only institutional clients (with professional programmers) use them.


Anyway, that's all IMHO. Personally, I wish MQL was just a C++ API. But then again, I am sure it would not be the success it is today if that was so.


FYI, MQL5 is event driven, no need to wait for ticks.

I agree for the reasons of the language and approach taken, I don't have an issue with that. I just find it frustrating at times and function points illustrate this perfectly, so they expose the ability to call DLL's great, so now you find a win api call you interested and it requires you to use a function pointer, oops can't do that, ok you can get arround the problem most of the times but wouldn't life be easier if......


Yes I am aware of the events in mql5 and its a start. So my next question would be can you raise an event externally. Eg. Say you have a DLL that when loaded spawns a new thread that is kept alive for the life of the chart, can you raise the event from within the DLL.


So how do you feel about the statement of making infrequent call's to dll's all because they wrap a level of isolation on every call to the dll.


 
pfx:

I agree for the reasons of the language and approach taken, I don't have an issue with that. I just find it frustrating at times and function points illustrate this perfectly, so they expose the ability to call DLL's great, so now you find a win api call you interested and it requires you to use a function pointer, oops can't do that, ok you can get arround the problem most of the times but wouldn't life be easier if......

I have had my own frustrations with the lack of pointers and interfacing DLL's, etc. As I said, I prefer it if it was just a C++ API (although IMHO I think MT4 wouldn't have been popular if that were the case).


Yes I am aware of the events in mql5 and its a start. So my next question would be can you raise an event externally. Eg. Say you have a DLL that when loaded spawns a new thread that is kept alive for the life of the chart, can you raise the event from within the DLL.

As far as I know - no. But honestly, I have very little experience so far with MT5, so I'm really not sure. Should ask on MQL5 forum...


So how do you feel about the statement of making infrequent call's to dll's all because they wrap a level of isolation on every call to the dll.

Yeah, that pisses me off as well. It would really cripple the effectiveness of DLL's. I suspect the reasoning behind this is the same reasoning behind giving a simplified language - to protect the masses of non-professional programmers from badly coded DLL's.


If MQ's basic assumption is that the majority of coders for their platform will be non-professional/beginning programmers, then most of their design declensions actually make sense. Of course these design decisions make life hard for any professional programmers who want more power. Eventually it's a kind of design trade-off - would u rather have a fully C/C++ compliant platform that will likely be less popular, hence will have less community-support, less brokers to choose from, etc., OR would u rather have a simplified programming environment that would attract the masses, give u many brokers to choose from and give u this online community?


Anyway, that's just my opinion.

 
gordon:

I have had my own frustrations with the lack of pointers and interfacing DLL's, etc. As I said, I prefer it if it was just a C++ API (although IMHO I think MT4 wouldn't have been popular if that were the case).


As far as I know - no. But honestly, I have very little experience so far with MT5, so I'm really not sure. Should ask on MQL5 forum...


Yeah, that pisses me off as well. It would really cripple the effectiveness of DLL's. I suspect the reasoning behind this is the same reasoning behind giving a simplified language - to protect the masses of non-professional programmers from badly coded DLL's.


If MQ's basic assumption is that the majority of coders for their platform will be non-professional/beginning programmers, then most of their design declensions actually make sense. Of course these design decisions make life hard for any professional programmers who want more power. Eventually it's a kind of design trade-off - would u rather have a fully C/C++ compliant platform that will likely be less popular, hence will have less community-support, less brokers to choose from, etc., OR would u rather have a simplified programming environment that would attract the masses, give u many brokers to choose from and give u this online community?


Anyway, that's just my opinion.

I see what your saying, I just think they should be able to accommodate both camps. I find it strange though, in Mql5 it now makes it much harder for novice developers. Too many professional programmers still get OO wrong, how the heck is a novice going to get it ;)

 
pfx:

I see what your saying, I just think they should be able to accommodate both camps. I find it strange though, in Mql5 it now makes it much harder for novice developers. Too many professional programmers still get OO wrong, how the heck is a novice going to get it ;)

I think it's to early to tell... But as I understand they are attempting to design the platform/language so as simple c-style procedural code can still be written and so novices can start with that. We'll c when the book is out. I won't be surprised if it will go over writing a simple MQL4-style EA first (which would be much easier for beginners to understand) and only then dive into OOP.

Reason: