Managed (.NET) dll working from installation folder but not from terminal_data_directory\MQL4\Libraries
Here is some more info.
The problem occurs when the EA is calling DLL A which is calling another DLL B.
In this case only when the DLLs are in the installation folder it works as expected. But when the DLLs are in the libraries folder we get the exception.
Please find attached EA + c# projects
Thanks
Any news on this issue?
you may run the terminal in a Portable mode (as in previous MetaTrader 4 builds). In that mode, the data is stored and recorded in the installation folder. To do this, use "/portable" key
I have added ExternalPing2 and SetPathForExternal methods in MQL4. I use Assembly.LoadFile in C# and it works. I can only think of this way. I am sure there is other way which is better than this.
#import "MT4.Test.dll" int InternalPing (); int ExternalPing (); int ExternalPing2 (); int SetPathForExternal (string terminal_data_libpath); #import //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnInit() { string terminal_data_libpath = TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL4\\Libraries\\"; SetPathForExternal(terminal_data_libpath); Print("InternalPing: ", InternalPing()); Print("ExternalPing2: ", ExternalPing2()); }
I have a Compilation error.(pic attached)
does my visual studio need a reference "RGI..."?
i tried to add reference RGI... but could not find.
what am i doing wrong?
I have a Compilation error.(pic attached)
does my visual studio need a reference "RGI..."?
i tried to add reference RGI... but could not find.
what am i doing wrong?
Yes, you need RGiesecke.DllExport reference.
Right-click on MT4.Test project, then click "Manage NuGet Packages..." --> see Capture06_59238.PNG
Then find "UnmanagedExports" --> see Capture07_59238.PNG.
Try :-)
I have added ExternalPing2 and SetPathForExternal methods in MQL4. I use Assembly.LoadFile in C# and it works. I can only think of this way. I am sure there is other way which is better than this.
Anton, nice workaround,
Thanks
Ruby
Here is some more info.
The problem occurs when the EA is calling DLL A which is calling another DLL B.
In this case only when the DLLs are in the installation folder it works as expected. But when the DLLs are in the libraries folder we get the exception.
Please find attached EA + c# projects
Thanks
Hello Ruby! I'm in your exactly workaround but I can't get it works with two DLLs. Please, can you specifiy me what folder do you refer with "installation folder". I always get the exception. Thanks!
I realise I'm a little late to the party here, but I just thought I'd share a tidier method of accomplishing this.
In the static constructor of the class that contains the [DllExport] methods, hook an event handler to AppDomain.CurrentDomain.AssemblyResolve - this will get called into every time the framework tries to resolve an external DLL reference.
Within this handler, you can split off the first part of the ResolveEventArgs.Name field to get the required DLL name, and then combine with Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) to get the full required DLL path to be used in conjunction with Assembly.Load
In this way, no extra method to set the MT4 library path is required, and no manual specification of DLLs to load using magic strings is required.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I have a c# DLL which is working great when placed in MT4 (build 765) installation Folder.
However, when trying to move the DLL to terminal_data_directory\MQL4\Libraries I'm getting "Unhandled exception 0xE0434352".
I would like to emphasize that it's not a problem of calling managed code from unmanaged code - it is working perfectly from MT4 installation folder.
What may be the problem and how can it be resolved. I really need the DLL to be placed in the MQL4\Libraries directory.
Thanks