Asynchronous and multi-threaded programming in MQL - page 2

 
Koldun Zloy:

I will translate what you have already been told by a representative of the MT development company:

You cannot create threads from MQL. Not even with WinAPI.

You can only do this by writing your own DLL.

WinAPI and uses standard dll !

kernel32.dll
user32.dll

etc.

Multithreading work with WinAPI functions is intended, not with mql functions.
But it's unfortunate that you cannot multi-thread work with mql functions.

 
Roman:

WinAPI and uses standard dlls !

kernel32.dll
user32.dll

Hmm, exactly the opposite, WinAPI is implemented as dynamic libraries kernel32.dll , user32.dll...

You've never tried to write in pure C++ a usual Windows window with the text "Hello Word!" - There are examples on the net, write your first "Hello Word! - it'll clear up by itself ;)

 
Igor Makanu:

hmm, exactly the opposite: WinAPI is implemented as dynamic libraries kernel32.dll , user32.dll...

You've never tried to write in pure C++ a usual Windows window with the text "Hello Word!" - There are examples on the net, write your first "Hello Word! - a lot will clear up by itself ;)


Standard meant standard Windows dlls, standard does not mean they are static .lib

Igor, you're going the wrong way...
What does "Hello Word!" have to do with the initialization of the dll, and call functions from it in your thread !

For example:
There is the WinAPI function MessageBoxW();
It must be called in its own thread.

For this you need to initialize the dll itself and the exported function, can you give an example how to do this correctly?

LoadLibraryW("user32.dll");
GetProccAddress(hMyDll, "MessageBoxW");
FreeLibrary(hMyDll);
и т.д.

Then after initialization, call MessageBoxW(); with CreateThread();
After the function is executed, release the resource and close the thread.
Give me an example of how to do it correctly in mql ?

 
I'm currently working on a multi-threaded system. But not in MCL, but in standard C++. Ah, how many rakes there are.)
 
Roman:


Standard meant the standard Windows dll, standard does not mean they are static .lib

Igor, you're going in the wrong direction...
What does "Hello Word!" have to do with the initialization of the dll, and call functions from it in your thread !

For example:
There is the WinAPI function MessageBoxW();
It must be called in its own thread.

For this you need to initialize the dll itself and the exported function, can you give an example how to do this correctly?

Then after initialization, call MessageBoxW(); with CreateThread();
After execution of the function, release the resource and close the thread.
Give me an example of how to do it correctly in mql ?

You are on the wrong track, you have been told - write a dll (in which you must allocate memory and register a new thread! - then carefully destroy everything on exit!) and call it from MQL

where memory allocation and process registration are in your example? The MessageBox call means that the MQL program has allocated its resources but hasn't created a separate thread. I don't even want to check it, but the terminal should freeze when MessageBox is called

 
Igor Makanu:

You're going the wrong way, I told you - write a dll and call it from MQL

where in your example is memory allocation and process registration? the fact that you called MessageBox - this only means that the MQL program has provided its resources but not created a separate thread. I don't even want to check it, but when you call MessageBox, your terminal should freeze

Igor, I cited the initialization dll functions as an example to understand what I'm talking about. But I'm not aware how to do it correctly in mql, pure C++ can be misleading.
The peculiarity of mql itself may cause confusion. That's why I asked for help on the forum, not Google.
Why do I need to write a dll, when WinAPI is built on dll, and callable functions are already inuser32.dll, for example
? I've created the topic to understand the question how to do it correctly in mql, and you tell me where to
allocate memory and register the process.
Show me a proper example how to do it in mql?
Or direct me to a good guide.

 
Roman:

Igor, I gave the dll initialization functions as an example to understand what I mean, but I don't know how to do it correctly in mql, pure C++ can be misleading.
The peculiarity of mql itself may cause confusion. That's why I asked for help on the forum, not Google.
Why do I need to write a dll, when WinAPI is built on dll, and callable functions are already in user32.dll, for example
? I've created the topic to understand the question, how to do it correctly in mql, and you tell me where
memory allocation and process registration is)).
Show me a proper example how to do it in mql?
Or direct me to a good guide.

You can't create a thread from mql program, even using WinAPI.

 
Roman:

Igor, I gave an example of dll initialization functions to understand what I mean, but how to do it correctly in mql, I'm not aware of, pure C++ can be misleading.
The peculiarity of mql itself may cause confusion. That's why I asked for help on the forum, not Google.
Why do I need to write a dll, when WinAPI is built on dll, and callable functions are already in user32.dll, for example
? I've created the topic to understand the question, how to do it correctly in mql, and you tell me where
memory allocation and process registration is)).
Show me a proper example how to do it in mql?
Or direct me to a good guide.

Once again, this is not done by means of MQL, you solve the problem from the other side - from the tail side, not from the head!

You write a dll - call it from MQL and pass data to the dll, and if you need to continue the MQL program (complex calculations), you create a new thread in the dll and process the data in this thread

You can read how to write a dll - search the forum for "dll" and you will find about 20 articles

There are no tutorials, but the resource you will use to write a dll, so look for solutions on how to create threads and so on.

 
Dmitry Fedoseev:

You can't create a flow from an mql program, even using WinAPI.

Forum on trading, automated trading systems and strategy testing

Asynchronous and Multithreaded Programming in MQL

MetaQuotes Software Corp., 2019.07.24 16:31

You can't call MQL functions from a DLL.

But it is possible to run multiple threads via DLL calls so that they work independently of MQL5 in their environment.

For example, you prepare data from MQL, place it somewhere or pass it to DLL, which in its turn will execute the task in multiple threads and return the result through additional function.


Calling Windows API functions is a call from dll, it means that threads can be created for Windows API functions usingCreateThread();
It is not for nothing
that CreateThread(); was ported to the standard mql library.

 
Roman:

Call of Windows API functions is a call from dll, so for Windows API functions it is possible to create threads usingCreateThread();
CreateThread(); was ported to the standard mql libraryfor a reason.

no one ported anything, what you see in the package are just function signatures.

to create a flow, you need a function body - this is the body that will run in the flow!

To register a thread in Windows you need to fill in the structure:

HANDLE CreateThread(
  LPSECURITY_ATTRIBUTES   lpThreadAttributes,
  SIZE_T                  dwStackSize,
  LPTHREAD_START_ROUTINE  lpStartAddress,
  __drv_aliasesMem LPVOID lpParameter,
  DWORD                   dwCreationFlags,
  LPDWORD                 lpThreadId
);

seelpStartAddress - this is the entry point address of the function that will run in the thread, don't worry aboutmemory allocation

to solve this problem, you need to find an opportunity to get the address of MyFunc() - in memory, and it is absent - well, nowhere at all ... none!


I don't know how else to explain the problem ... which does not really exist ))))