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

 
MetaDriver:

I've been shyly suggesting for a month that we should make a wiki-tutorial on mql5, filled by the community. This would solve the problems with the mega-tutorial. Authors could even be rewarded with credits for especially visited articles.

The wiki engine is free and available.

// If Metaquotes won't do it, someone else could do it on an external site. I, for one, am considering it.

For external sites, there's a problem - we have copyright on our material. And when creating an outside wiki, almost 100% of the text will be copypaste of our materials.

One could argue that public wikis are a utopia. The idea of public wikis has been buried in practice for a long time. Look how much effort we put into the development of our communities and documentation. It's a lot of money and daily work.

The solution to the issue lies in the area of managed content creation with mandatory delivery to each user's terminal. This increases the efficiency of mass familiarisation from a negligible 0.00x% to a very realistic 3-5%.

We increase the volume and connectivity of MQL5 materials on a daily basis. The documentation project(MQL5 language, help, multi-language) takes a very large share in our work.

 
Renat:

For external sites there is a problem - we have copyright on our materials. And when creating an external wiki, almost 100% of the text will be copypasted from our materials.

It can be argued that public wikis are a utopia. The idea of public wikis has been buried in practice for a long time. Look how much effort we put into the development of our communities and documentation. It's a lot of money and daily work.

The solution to the issue lies in the area of managed content creation with mandatory delivery to each user's terminal. This increases the efficiency of mass familiarisation from a negligible 0.00x% to a very realistic 3-5%.

We increase the volume and connectivity of MQL5 materials on a daily basis. The documentation project(MQL5 language, help, multi-language) takes a very large share in our work.

What if we revive contests under the tutorial. After all, newcomers are asking for a textbook.

Make a multi-stage contest, participants register, submit a textbook plan, 50% are eliminated, the rest are paid $20 each, go to the second stage, etc.

Until the end of the marathon will reach the end of the few but with the best works. Set real terms of creation with half a year, break it into stages and everything will work out.

 

That's a very interesting and useful article on general C++ and .NET interop.

The most simple strategy to implement is "2.4. C++/Cli wrapper class", because you can use .NET API in C++/cli without any hassle, so the only glue code is a small and straightforward class that holds "gcroot".

This approach was chosen as a ground for implementation of http://www.nquotes.net - a library which allows MQL programming in C#.

Although the first version only supports MQL4, but will definitely be ported to MQL5 in future versions.

NQuotes : MetaTrader (MT4) and C#/.NET bridge
  • www.nquotes.net
Debugging in Visual Studio IDE is possible. You can inspect values, place breakpoints and inspect execution step by step. Have a nicer experience than "Print" debugging in pure MQL. Compatible API NQuotes has an API that is compatible with MQL. It is quite easy to get started for MQL4 developers, while others can use the official...
 

Great article, very, very handy. But...

I have a slight bug with Visual Studio. If I create a new project using the template and build it, VS has no problem. I can then save the new project (including built dll) to disk, in a solution folder. The dll runs fine. However, if I go back into the saved project in VS, it complains about project "RGiescke.DllExport.targets" not being found or being on disk, although the file is there.

I guess its a problem with the project file.....

 

Very good tutorial, I like this.

big Thanks. 

 

Hi Investeo,

Thanks for this article it was very useful, though seems that i faced to some issue trying to use template from RGiesecke.

When i created and built a DLL i use DLL Export Viewer to check names of the exported functions to be able to find and call them via GetProcAddress. Unfortunately DLL itself is loading fine within LoadLibrary function but GetProcAddress returns error 127 - Function not found. At the same time DLL Export Viewer shows that neither of my functions were exported ...

Could you please suggest what can be wrong with my code?

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

namespace ClassLibrary1
{
    public class Class1
    {
        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        public static extern int MessageBox(IntPtr hWnd, String text, String caption, uint type);

        [DllExport("Demo", CallingConvention = CallingConvention.StdCall)]
        public static void Demo()
        {
            MessageBox(new IntPtr(0), "Demo", "Demo", 0);
        } 
    }
}

And then in Win 32 Console application i am doing the following :

HMODULE x1 = LoadLibrary(L"ClassLibrary1.dll");

        if (!x1) 
        {
                MessageBox(0, L"ERROR", L"Library", 0);
                return 0;
        }

        FARPROC x2 = GetProcAddress(x1, "Demo");

        DWORD error = GetLastError();

        if (!x2) 
        {
                MessageBox(0, L"ERROR", L"Proc", 0);
                return 0;
        }

Thanks, Art

 
Renat:

By the way, MetaTrader 5 has been able to natively import functions from DLLs written in .NET for several builds now

We have specially added such support and now there is no need to use workarounds.

I have not found information on how to import .Net functions. Who can, please share a link or a simple example.
 
a.p:
I can't find information how to make .Net function impromptu. Who can, please share a link or a simple example.

Switch on "Show all file types" in the editor navigator, grab your DLL with a mouse and throw it into the MQL5 window of the programme.

You will most likely be surprised by the result.

Документация по MQL5: Программы MQL5
Документация по MQL5: Программы MQL5
  • www.mql5.com
Программы MQL5 - Документация по MQL5
 
Renat:

Switch on "Show all file types" in the editor navigator, grab your DLL with a mouse and throw it into the MQL5 window of the programme.

You will probably be surprised by the result.

cool.

If I could insert all functions from the DLL at once.

 
Renat:

Switch on "Show all file types" in the editor navigator, grab your DLL with a mouse and throw it into the MQL5 window of the programme.

You will probably be surprised by the result.

Tried it, MetaEditor crashes

P.S.
Win8 Enterprise 64
MetaEditor build 842
.Net lib has one function:
public static int Add(int value1, int value2)
{
return value1 + value2;
}