MetaTrader (MQL4) > .DLL (Delphi/Pascal) > .jar (Java) | Java-Thread seems to close immediately when opened via .dll (ShellExecute) via mql-call

MetaTrader (MQL4) > .DLL (Delphi/Pascal) > .jar (Java) | Java-Thread seems to close immediately when opened via .dll (ShellExecute) via mql-call

Manage alerts

Loading saved threads...

Duke · External communityPost link
External question — Stack Overflow Stack Exchange Author: Duke Original post: https://stackoverflow.com/questions/76024454 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. (I use Windows 11 Home) To establish a communication between MetaTrader4 and my own Java Application I want to use stdin and stdout pipes. At this moment, I try to open my .jar from a .dll called by mql. But when I start my MQL Expert, import the dll (successful), I only get a blink of an eye console window. Also I cant find a matching thread in taskmanager My Java: import javax.swing.*; public class SystemOutTest { public static void main(String[] args) throws InterruptedException { JFrame frame = new JFrame("Text Window"); JLabel label = new JLabel("Hello, World!"); frame.add(label); frame.setSize(200, 100); frame.setVisible(true); Thread.sleep(9000); } } My .dll: library JarLauncher; uses Windows, ShellAPI; function LaunchJar(const AFileName: string; const AArguments: string): Integer; stdcall; var JavaPath: string; begin JavaPath := 'C:\Program Files (x86)\Java\jre1.8.0_361\bin\java.exe'; Result := ShellExecute( 0, nil, 'java.exe', '-Xmx1024M -Xms1024M -jar testpilot.jar', nil, SW_SHOW ); end; exports LaunchJar; begin end. And my MQL: #import "JarLauncher.dll" int LaunchJar(string AFileName, string AArguments); #import void OnInit() { // string jarFile = "C:\\path\\to\\testpilot.jar"; string jarFile = "testpilot.jar"; string arguments = ""; int result = LaunchJar(jarFile, arguments); if (result <= 0) { Print("Failed to launch JAR file!"); } else { Print(result); } Sleep(9000); } I know MT4 is 32Bit, so I got my Lazarus and Eclipse and JRE to 32Bit. I get no Errors. Got through some trouble there (ERR 126, file not found), so I am confident, that my MQL finds the dll and executes fine. My Output in MT4 Console is: 2023.04.15 20:43:28.558 maybeload [DJI30],H1: 42 2023.04.15 20:43:26.064 Expert maybeload [DJI30],H1: loaded successfully I think 42 is no Error Code but a Process Handle? In my dll I played around with ShellExcecute with different Variations of java.exe and full path and javaw.exe and -jar argument and also SW_SHOWNORMAL and SW_SHOWDEFAULT and SW_SHOW. Nothing changed a bit. I can start my .jar from cmd and from explorer (doubleclick) without Problems and see the window. I couldnot run it via rundll32, probably because I messed up the command. I figured it could be some problem with MQL Thread Handling... but im stuck since days now. Thank you very much!
Quote
Report
Marco van de Voort · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Marco van de Voort Original post: https://stackoverflow.com/a/76083911 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. You seem to assume that Pascal string = Java string. They are not the same. Rewrite the interface to use pchar in Pascal and and read up on JNI options in Java to interface to (char *) Probably char[].
Quote
Report

Post Reply

Checking account access…