Download MetaTrader 5

Managed (.NET) dll working from installation folder but not from terminal_data_directory\MQL4\Libraries

To add comments, please log in or register
Install apps from the library right in MetaTrader. It is easy!
TornadoFX Ltd.
187
Ruby Salton 2015.05.24 19:55 

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 


TornadoFX Ltd.
187
Ruby Salton 2015.05.25 09:01  

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 

Anton79
22
Anton79 2015.06.07 16:42  
I have the same problem...
Samuel Cardonis
157
Samuel Cardonis 2015.10.19 16:20  

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 

Anton Nel
36954
Anton Nel 2015.10.21 07:36  

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());
}

 

Files:
Samuel Cardonis
157
Samuel Cardonis 2015.10.21 12:46  

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? 

Files:
Capture.PNG 29 kb
Anton Nel
36954
Anton Nel 2015.10.21 15:57  
Samuel Cardonis:

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 :-)

TornadoFX Ltd.
187
Ruby Salton 2015.10.26 10:10  
Anton Nel:

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 

lake274
6
lake274 2015.10.31 04:10  
Ruby Salton:

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!
Anton Nel
36954
Anton Nel 2017.01.19 12:50  
lake274:
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!
Example for "installation folder" is C:\Program Files (x86)\FxPro - MetaTrader 4\
smimon
166
smimon 2017.01.28 11:43  

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. 

12
To add comments, please log in or register