I've recently had a request from a member to show how to create a DLL with window(s) that is used by an EA rather than an indicator.
As mentioned before in other threads (and most people know) Indicators run in MT4s main application thread. This means that if you create non modal windows in your DLL they will work fine since the DLL windows messages will be processed by the MT4 main app.
EAs on the other hand, each run in their own thread. MT4 does not provide a message handling loop within the EA threads and so it is more problematic to show DLL windows.
The way around this is to create a new thread in your DLL which will provide the message processing capabilites a window(s) requires.
Whilst the coding of a DLL to interact with a single EA is slightly easier this example shows how to deal with multiple EAs Using the same DLL and window, and can be used for either single or multiple EA users.
I've tried to keep the code as simple as possible whilst providing a decent level of functionality, or at least to show how flexible this basic DLL is, all the while highlighting the pitfalls and showing how to avoid them.
Conversion to any C compiler shouldnt cause any major headaches provided the coder knows how to create a basic DLL and get it running within an Mt4 EA or indicator.
To sum up, the framework of this DLL can be easily be expanded to produce a complex (interactive) user interface to control or enhance any EA .
I've commented the Delphi source code quite extensively, but havent added much to the EA (MQ4) as its short 'n sweet and self explanitory.
If you dont know where the attached files need to go then you probably should'nt be playing with them, but just for the sake of it, the following files need to go in the stated locations :
DLL file -> MT4\experts\libraries
MQ4 file -> MT4\experts
All the other files are the Delphi project Source code and need to be placed in a single folder.
As a final caveat it was written using Delphi V4 running on Win XP With MT4 Build 509. I dont know if it will compile on later versions of Delphi or whether it will run correctly on later versions of windows but I cant see any reasons why it wouldnt.
I hope this helps anybody out there struggling to achieve what can be a pain in the a$$ to code.
*************************************************************************************
Appologies to all initial 7 downloaders. I have debugged the DLL code and found two errors in the initial release.
These errors were :
Bug : Incorrect freeing of objects during deint unless the DLL is unloaded from memory
Symptom : If you have this EA(s) open and recompile the MQ4 file then It will not initialise correctly
Bug : Failure to wait for DLL thread to create our main DLL window.
Symptom : Fails to initialise correctly in an unpredictable and often inconsistent manner.
As mentioned before in other threads (and most people know) Indicators run in MT4s main application thread. This means that if you create non modal windows in your DLL they will work fine since the DLL windows messages will be processed by the MT4 main app.
EAs on the other hand, each run in their own thread. MT4 does not provide a message handling loop within the EA threads and so it is more problematic to show DLL windows.
The way around this is to create a new thread in your DLL which will provide the message processing capabilites a window(s) requires.
Whilst the coding of a DLL to interact with a single EA is slightly easier this example shows how to deal with multiple EAs Using the same DLL and window, and can be used for either single or multiple EA users.
I've tried to keep the code as simple as possible whilst providing a decent level of functionality, or at least to show how flexible this basic DLL is, all the while highlighting the pitfalls and showing how to avoid them.
Conversion to any C compiler shouldnt cause any major headaches provided the coder knows how to create a basic DLL and get it running within an Mt4 EA or indicator.
To sum up, the framework of this DLL can be easily be expanded to produce a complex (interactive) user interface to control or enhance any EA .
I've commented the Delphi source code quite extensively, but havent added much to the EA (MQ4) as its short 'n sweet and self explanitory.
If you dont know where the attached files need to go then you probably should'nt be playing with them, but just for the sake of it, the following files need to go in the stated locations :
DLL file -> MT4\experts\libraries
MQ4 file -> MT4\experts
All the other files are the Delphi project Source code and need to be placed in a single folder.
As a final caveat it was written using Delphi V4 running on Win XP With MT4 Build 509. I dont know if it will compile on later versions of Delphi or whether it will run correctly on later versions of windows but I cant see any reasons why it wouldnt.
I hope this helps anybody out there struggling to achieve what can be a pain in the a$$ to code.
*************************************************************************************
Appologies to all initial 7 downloaders. I have debugged the DLL code and found two errors in the initial release.
These errors were :
Bug : Incorrect freeing of objects during deint unless the DLL is unloaded from memory
Symptom : If you have this EA(s) open and recompile the MQ4 file then It will not initialise correctly
Bug : Failure to wait for DLL thread to create our main DLL window.
Symptom : Fails to initialise correctly in an unpredictable and often inconsistent manner.
Attached File(s)
EAandDLLexamplecode.zip
202 KB
|
1,113 downloads