Tuesday, August 2, 2011

Write C# DLL for Metatrader (CSharp)

Those C# developers who would like to write a DLL in C# for Metatrader instead of in C++ now have a path to that end. There is a very interesting article titled "Exposing C# code to MQL5 using unmanaged exports" that I've just read. I use MT4 (MQL4) instead but the idea is still valid.

Read/skim the article and read section 2.5 onward.
Exposing C# code to MQL5 using unmanaged exports - MQL5 Articles

Read the directions, then download the Template for C# "Unmanaged Export Library" and place the zip file in the right directory (by following the directions on that page):
C# Project Template for Unmanaged Exports

Load Microsoft Visual Studio 2010 (or  Microsoft Visual C# 2010 Express) and select the "Unmanaged Export Library" template. Follow the code samples. Hope this helps somebody!

You can find sample code for creating a C# dll with the Unmanaged Export Library here  including  a download for the visual studio solution and the MT4 sample script.

7 comments:

Anonymous said...

Thanks for posting these links Patrick! Saved me a ton of time chasing this all down. - Drew

Patrick White said...

You're welcome Drew! Drop a note to let us know about your progress.

Anonymous said...

Well I'm almost there, but I'm getting a compile error as MS seemed to have changed some things since the template was written. The error I'm getting is "Cannot find lib.exe in C:\Program Files (x86)..."

It seems to create both the 64bit and 32bit DLL's though regardless. I have tried both with my EA and although it compiles correctly, it stops operating when I add the function call to my test "AddMe" function. If you have any ideas I would appreciate it, otherwise I'll post if I find something. - Thanks!

Anonymous said...

Going to post int the sub-thread that I just noticed about the issues.

Anonymous said...

Thank you very much.

Patrick White said...

You're welcome!

Anonymous said...

Hi Patric,
Thank you very much for the idea and code. Could you please give me an example on how to get data from a mysql table ?
Thanks