Importing DLL functions in MQL4

 
Hello! im following this tutorial
http://www.codeguru.com/csharp/.net/cpp_managed/windowsservices/article.php/c14735/Exporting-NET-DLLs-with-Visual-Studio-2005-to-be-Consumed-by-Native-Applications.htm

to import a custom function created in c#, in my case im downloading data from web in c# but in visual sutdio 2012 and my machine is x64, do i have to do somehting different? metatrader is able to load .net 4.5 dll functions? i have a compiled and working systems in visual studio, but when i tried to call this dll wrapper in metatrader i get this error

2013.12.09 12:16:43 NasdaqDowData NZDUSD,M30: function 'GetData' call from dll 'GetDataWrapper.dll' critical error e0434352 at 76E8C41F.

Do you know what does it mean? what am im missing to do?
Thank you!

 
Mql4 can not use c# DLLs directly, only 'regular' ones.
 
WHRoeder:
Mql4 can not use c# DLLs directly, only 'regular' ones.

yes i know...this is why I use a wrapper in c++, but i cant use it. I dont know if its because you need a concrete .Net version, im using 4.5 (visual Studio 2012) or if im missing something
 
reivaj117: or if im missing something
You are missing the fact that this is a MT4 forum, not a DLL or .net forum. You are off topic.
 
WHRoeder:
You are missing the fact that this is a MT4 forum, not a DLL or .net forum. You are off topic.

this is a dll mt4 function related question, that maybe someone in the past has face with something similar, finally i did in pure C++ is the easiest way. Thank you!
 
reivaj117: this is a dll mt4 function related question
No it is not. You already said you know Mt4 can not call a .net DLL and that you using a wrapper:
reivaj117: yes i know...this is why I use a wrapper in c++,
Your problem is between a DLL and a .net DLL and that is NOT mt4 related. You are off topic and apparently no one here knows your answer.
 
reivaj117:
2013.12.09 12:16:43 NasdaqDowData NZDUSD,M30: function 'GetData' call from dll 'GetDataWrapper.dll' critical error e0434352 at 76E8C41F.

"e0434352" simply means ".NET exception", so it's impossible to give much help from the amount of information you have provide.

Three main possibilities:

  • There is an untrapped exception inside the .NET code, e.g. a download is failing and you are allowing that exception to bubble up into the wrapper DLL and into MT4 rather than trapping it.
  • The error means that the wrapper DLL cannot locate the .NET DLL.
  • You almost certainly need to compile the .NET assembly as x86 rather than AnyCPU. Otherwise, on a 64-bit machine, you may well have 32-bit MT4 trying to use 64-bit .NET code.
 
WHRoeder:
Mql4 can not use c# DLLs directly, only 'regular' ones.

If the C# functions are not exported, then what you state is correct.

However, C# DLLs can be effectively turned into native DLLs by exporting the function calls. Then these exported DLLs may be directly referenced the same as 'regular' DLLs by MQL4. There is an article on the MQL5 site detailing exactly how to perform this export of C# DLL functions that also applies to MQL4: 

https://www.mql5.com/en/articles/249 

 
reivaj117:
Hello! im following this tutorial
http://www.codeguru.com/csharp/.net/cpp_managed/windowsservices/article.php/c14735/Exporting-NET-DLLs-with-Visual-Studio-2005-to-be-Consumed-by-Native-Applications.htm

to import a custom function created in c#, in my case im downloading data from web in c# but in visual sutdio 2012 and my machine is x64, do i have to do somehting different? metatrader is able to load .net 4.5 dll functions? i have a compiled and working systems in visual studio, but when i tried to call this dll wrapper in metatrader i get this error

2013.12.09 12:16:43 NasdaqDowData NZDUSD,M30: function 'GetData' call from dll 'GetDataWrapper.dll' critical error e0434352 at 76E8C41F.

Do you know what does it mean? what am im missing to do?
Thank you!


I haven't worked with the tutorial you reference. However there is a (fairly) easy method to export DLL functions from C# so that they may be imported with MQL4, the same as regular DLLs. This method makes use of a NuGet package "Unmanaged Exports (DllExport for .Net)" that does the necessary DLL function exports for you.

There is a fully functional demo on:

http://vb6-to-csharp.blogspot.com/2014/05/code-to-export-c-dll-to-metatrader.html 

(Code to Export C# DLL to Metatrader Build 600+) that gives you both sides - the C# DLL export side and the MQL4 DLL import side.

Reason: