Discussion of article "Exposing C# code to MQL5 using unmanaged exports" - page 2

 
How to use a .Net Assembly in Delphi without registering it in the GAC or COM?
How to use a .Net Assembly in Delphi without registering it in the GAC or COM?
  • stackoverflow.com
i have a simple task: is it possible to write a Delphi DLL and put a .Net Assembly (with only one interface with 4 methods and one class implementing the interface) besides it and call it from the
 

*Huge* thanks for writing this article!  It's very well written and the multitude of examples are extremely helpful.

The big hurdle for me was figuring out the variable types and how to pass them back and forth. (especially arrays and strings)  It would be great to see some shared C# libraries for Metatrader.  Once I learn more and build some useful libraries, I'll see if I can contribute them.

You have saved me a lot of time instead of learning by trial and error.  Thanks for sharing your knowledge.

It's appreciated!  :-)

 

Hi

I have a problem that suddenly (?) my DLL function returns error message "Cannot find 'Add' in 'TestMe.dll'. This is a simple example, using your code:

using System;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;

namespace Testme
{
    class Test
    {

        [DllExport("Add", CallingConvention = CallingConvention.StdCall)]
        public static int Add(int left, int right)
        {
            return left + right;
        }       
    }
}
 

Using it in an .mql file:

#import "Testme.dll"
   int Add(int left,int right);  
#import

void OnStart()
  {
//---
   for(int i=0; i<3; i++)
     {
      Print(Add(i,666));     
     }
  }

 

--> Cannot find 'Add' in 'Testme.dll'

 

Is there a change in how to call DLLs that I have missed? 

 

Any opinion is greatly appreciated

Thomas 

 

Hi

 I also have a problem suddenly (it worked at first, but ...),  when I compiled the sample dll, I got

Assembling 'C:\Users\internal228\AppData\Local\Temp\tmpAFBE\UELTest.x86.il'  to DLL --> 'C:\Users\internal228\Documents\Visual Studio 2010\Projects\UnmanagedLibTest\UELTest\bin\Debug\x86\UELTest.dll'

Source file is UNICODE

***** FAILURE ***** 

UELTest

 

Anything I missed? 

Windows 7; VisualStudio 2010;

Any opinion is greatly appreciated.

Risan

 

**UPDATE**  Sorted it out thanks!


Hey there,

I followed the procedure entirely to write a dll in C# Express 2010.  The template did not work so I manually added the dll files in a new project and everything compiled nicely (maybe I did something wrong here).

I wrote two easy functions just to test if it works, and I'm testing out of Metatrader 4.  I get the following error:


2011.10.29 20:13:37    2000.01.03 00:00  Expert_NN_1_1 USDJPY,H1: cannot call function 'sum' from dll 'NN 1 DLL.dll' (error 127)


Any idea what might be the problem?  The DLL is loaded my MT4, I checked, but it does not want to call the function.  I noticed that this problem appears when trying to call a managed dll in MT4, but the procedure described in this article is supposed to solve the problem right?

Any help will be appreciated

Thanks!

 

Hi there,

Would just like to pass on my appreciation for such a well written article.

The site details for Robert Giesecke were invaluable.

I have learnt much. Not needing to write another C++ wrapper when I prefer VB.NET is a cool thing.

Many thanks. 

Cheers, 

Gordon 

 

Hi,

I have the same problem.... methods I decorate are not found in mt5!!

 

pls help!  (i'm using vs2010 and the template) 

 
Big request for a simple example of a function written in C# to access it from mt4(or mt5) ........... Pass values a and b to a function with Sharp and return the result to mt4(mt5)

in the article https://www.mql5.com/en/articles/249 compiled dll of the author works in mt4 and mt5 correctly!

but when I try to create my own compiled dll from the source of the author (in VisualStudio 2010), this dll does not work (writes error 127)

all versions of .NET installed


// код C#

using System;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;



namespace TEST
{
class TEST
{
[DllExport("Add", CallingConvention = CallingConvention.StdCall)]
public static int Add(int left, int right)
{
return left + right;
}
}
}



namespace RGiesecke.DllExport
{

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
partial class DllExportAttribute : Attribute
{
public DllExportAttribute()
{
}
public DllExportAttribute(string exportName)
: this(exportName, CallingConvention.StdCall)
{
}
public DllExportAttribute(string exportName, CallingConvention callingConvention)
{
ExportName = exportName;
CallingConvention = callingConvention;
}
public CallingConvention CallingConvention { get; set; }
public string ExportName { get; set; }
}
}


// код МТ4
//+------------------------------------------------------------------+
#import "TEST.dll"
int Add(int a,int b);
#import

void start()
{
Comment(Add(3,2));
}
//+------------------------------------------------------------------+

What is the error?
Как открыть мир C# из MQL5 путем экспорта неуправляемого кода
Как открыть мир C# из MQL5 путем экспорта неуправляемого кода
  • 2011.02.09
  • investeo
  • www.mql5.com
В данной статье я представил различные методы взаимодействия между кодом, написанным на MQL5, и управляемым кодом на C#. Также я подготовил несколько примеров маршалинга структур MQL5 для C# и примеров вызова экспортированных функций DLL в скриптах на MQL5. Приведенные примеры могут служить основой для дальнейших исследований аспектов написания DLL в управляемом коде. Эта статья также открывает двери для использования в MetaTrader 5 множества библиотек, уже реализованных на C#.
 
who knows where and how templates are inserted in c-sharp, the reason is apparently only this

and how to template to engage?
 
panelektrik:
who knows where and how templates are inserted in c-sharp, the reason is apparently only this

and how to engage the template?

http://softblog.violet-tape.ru/2010/05/06/visual-studio-templates/

at the bottom for VS2010.

and useful information at the very bottom.

Visual Studio. Заготовки проектов
Visual Studio. Заготовки проектов
  • www.rootfront.com
В последнее время я не просто много, а очень много экспериментирую с кодом, подходами, написаниями каких-то тестовых сценариев и приложений. Результат, конечно, всегда разный, ну да не об этом сегодня пойдет речь. Постепенно начинаешь уставать от настройки стандартных проектов. Для проекта библиотек надо удалить класс, создаваемый там по...