opening windows form in a c++ DLL

 

hello, I'm trying to call a windows form that i compiled inside a DLL. I can successfully open the form and view it, but after i close the form it stops the indicator cold and doesn't proceed in the code and refuses to work again till meta-trader is restarted. i also cant delete the dll till meta-trader is restarted.


ex:

dll's function

extern "C" void __stdcall Run()
{

Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

Application::Run(gcnew Form1()); <------I can comment out this line and it works fine but there's no form obviously

<------------I know it gets this far in the dll (tested with an exit(0))

}


mql file

Run();

Alert("After run"); <--- alert never shows

 
Indicators can not wait or sleep or do long computations. Indicators run in the GUI thread of the terminal.
 
try starting a new thread in your dll and run the event loop (and all other GUI stuff) only from within this thread. This might either work immediately or it might cause some more minor (but solvable) difficulties but basically this is the only option you have: Use one separate dedicated thread for all your GUI stuff.and then use the usual means (as should be documented in the docs for your GUI framework) of messaging or synchronizing to communicate between all the MT4 function calls (which may all be from different threads) and your one main GUI thread.