.NET DLL calls from mq4. Is it possible? Any sample? - page 2

 
I will know and try to contact with him.
 
Thanks Rosh
 
I have read messages. I think, that the best help will be in a writing of clause method of use .NET in MQL before MC++.

I using this:

MQL4 expert

#import "mtermite.dll"
    bool ExpertClasterInitialize( string iContext, string iSimbol, int iDigits, int iSpread, double iPoint, double iTickSize, int iStopLevel, double iBid, datetime iStamp );
    bool ExpertClasterFinalize( string iContext );
    bool ExpertClasterUpdate( string iContext, double iBid, datetime iStamp, int iSpread, int iStopLevel );
#import
 
string Context = "@MetaTermit.Extension.dll";
string _Symbol;
 
int init() {
    _Symbol = Symbol();
    ExpertClasterInitialize( Context, _Symbol, MarketInfo( _Symbol, MODE_DIGITS ), MarketInfo( _Symbol, MODE_SPREAD ), MarketInfo( _Symbol, MODE_POINT ), MarketInfo( _Symbol, MODE_TICKSIZE ), MarketInfo( _Symbol, MODE_STOPLEVEL ), MarketInfo( _Symbol, MODE_BID ), MarketInfo( _Symbol, MODE_TIME ) );
    return(0);
}
 
int deinit() {
    ExpertClasterFinalize( Context );
    return(0);
}
 
int start() {
    ExpertClasterUpdate( Context, MarketInfo( _Symbol, MODE_BID ), MarketInfo( _Symbol, MODE_TIME ), MarketInfo( _Symbol, MODE_SPREAD ), MarketInfo( _Symbol, MODE_STOPLEVEL ) );
    return(0);
}
MC++ lib, cpp file Options /clr /noentry include C# Project library

#include "stdafx.h"
 
using namespace MetaTermit;
 
__declspec(dllexport) int __stdcall ExpertClasterInitialize( signed char* iContext, signed char* iSymbol, int iDigits, int iSpread, double iPoint, double iTickSize, int iStopLevel, double iPrice, unsigned int iStamp ) {
    return Extern::ExpertClasterInitialize( iContext, iSymbol, iDigits, iSpread, iPoint, iTickSize, iStopLevel, iPrice, iStamp );
}
 
__declspec(dllexport) int __stdcall ExpertClasterFinalize( signed char* iContext ) {
    return Extern::ExpertClasterFinalize( iContext );
}
 
__declspec(dllexport) int __stdcall ExpertClasterUpdate( signed char* iContext, double iPrice, unsigned int iStamp, int iSpread, int iStopLevel ) {
    return Extern::ExpertClasterUpdate( iContext, iPrice, iStamp, iSpread, iStopLevel );
}
C# lib example

namespace MetaTermit {
 
    using System;
 
    public unsafe static class Extern {
 
        public static bool ExpertClasterInitialize( sbyte* iContext, sbyte* iSymbol, int iDigits, int iSpread, double iPoint, double iTickSize, int iStopLevel, double iPrice, uint iStamp ) {
#if !DEBUG
            try {
#endif
                if ( iContext[ 0 ] != 0x40 ) return false;
                TermitContext context = Global.Context.Append( (IntPtr)iContext );
                if ( context.Claster == null ) {
                    ExpertClaster claster = Global.Claster.Append( context, new string( iSymbol ), iDigits, iSpread, iPoint, iTickSize );
                }
                iContext[ 0 ] = 0x00;
                Global.WindowControl();
                return true;
#if !DEBUG
            } catch {
                return false;
            }
#endif
        }
 
        public static bool ExpertClasterFinalize( sbyte* iContext ) {
#if !DEBUG
            try {
#endif
                if ( iContext[ 0 ] != 0x00 ) return false;
                Global.Context.Remove( (IntPtr)iContext );
                iContext[ 0 ] = 0x40;
                Global.WindowControl();
                return true;
#if !DEBUG
            } catch {
                return false;
            }
#endif
        }
 
        public static bool ExpertClasterUpdate( sbyte* iContext, double iPrice, uint iStamp, int iSpread, int iStopLevel ) {
#if !DEBUG
            try {
#endif
                if ( iContext[ 0 ] != 0x00 ) return false;
                TermitContext context = Global.Context[ (IntPtr)iContext ];
                if ( context.Claster == null ) return false;
                if ( context.Claster.Session.First.Context != context ) return false;
                context.Claster.Ticks.Add( DateTime.UtcNow, iPrice, (new DateTime( 1970, 1, 1 )).AddSeconds( iStamp ) );
                return true;
#if !DEBUG
            } catch {
                return false;
            }
#endif
        }
        
    }
 
}
For debug, need write Test application
 
You need location library, terminal root folder, if not using GAC

I now write new version, use .NET 3.0 libraries for tick diagram output...
Last alpha version http://community.xnsnet.ru/files/folders/44/download.aspx sources for 2005
Expert sources for this project http://community.xnsnet.ru/files/folders/64/download.aspx
 
xnsnet,
Thanks you very much for your example. I have been offline for the last couple of days so I will go through it and let you know how I go. Thanks once again.
 
Hello xnsnet, I have created a simple example with one menthod here is the mql, c++ and c# code. As you can see the saySomething method should return the integer 1234, however, when I run the MQL code with the wrapper.dll C++ file and the yenmaster. dll C# file the following crash details occur in the MetaTrade client and StrategyFX client:

mql:

#import "Wrapper.dll"
    int saySomething( int number );
#import
 
int init() {
    return(0);
}
 
int deinit() {
    return(0);
}
 
int start() {
    Print(saySomething(11));
    return(0);
}
c++:
#include "StdAfx.h"
#include "NetworkHelper.h"

using namespace YenMaster;

__declspec(dllexport) int __stdcall saySomething( int something ) {
return YenMaster::NetworkHelper::saySomething( something );
}

c#:

using System;
using System.Collections.Generic;
using System.Text;

namespace YenMaster
{
public unsafe static class NetworkHelper
{
public static int saySomething(int something)
{
return 1234; // "Something " + something;
}
}
}

Crash error message details:


There has been a critical error
Time : 2007.05.28 22:28
Program : Client Terminal
Version : 4.00 (build: 204, 25 Apr 2007)
Owner : MetaQuotes Software Corp. (MetaTrader)
OS : Windows XP Professional 5. 1 Service Pack 2 (Build 2600)
Processors : 2, type 586, level 6
Memory : 2086960/968048 kb
Exception : E0434F4D
Address : 7C812A5B
Access Type : NA
Access Addr : 00000000

Registers : EAX=020DE97C CS=001b EIP=7C812A5B EFLGS=00000202
: EBX=001E1DE8 SS=0023 ESP=020DE978 EBP=020DE9CC
: ECX=00000000 DS=0023 ESI=020DEA08 FS=003b
: EDX=00000025 ES=0023 EDI=E0434F4D GS=0000

Stack Trace : 79F97065 7A05B942 7A05B9EB 7A05B9F6
: 79E96791 79061526 79E7470B 00000000
: 00000000 00000000 00000000 00000000
: 00000000 00000000 00000000 00000000
Modules :
1 : 00400000 007BE000 C:\Program Files\MetaTrader 4\terminal. exe
2 : 02FA0000 00013000 C:\WINDOWS\system32\hccutils. DLL
3 : 02FD0000 0000D000 C:\Program Files\MetaTrader 4\experts\libraries\Wrapper. dll
4 : 03040000 00102000 C:\WINDOWS\WinSxS\x86_Microsoft. VC80. DebugCRT_1fc8b3b9a1e18e3b_8. 0.50727.42_x-ww_f75eb16c\msvcm80d.dll
5 : 0FFD0000 00028000 C:\WINDOWS\system32\rsaenh. dll
6 : 10000000 00014000 C:\Program Files\Dell\QuickSet\dadkeyb. dll
7 : 10200000 00120000 C:\WINDOWS\WinSxS\x86_Microsoft. VC80. DebugCRT_1fc8b3b9a1e18e3b_8. 0.50727.42_x-ww_f75eb16c\MSVCR80D.dll
8 : 20000000 002C5000 C:\WINDOWS\system32\xpsp2res. dll
9 : 5AD70000 00038000 C:\WINDOWS\system32\UxTheme. dll
10 : 5B860000 00054000 C:\WINDOWS\system32\netapi32. dll
11 : 5E380000 00089000 C:\WINDOWS\Microsoft. NET\Framework\v2. 0.50727\diasymreader. dll
12 : 5FD00000 0000D000 C:\WINDOWS\system32\MFC42LOC. DLL
13 : 605D0000 00009000 C:\WINDOWS\system32\mslbui. dll
14 : 662B0000 00058000 C:\WINDOWS\system32\hnetcfg. dll
15 : 71A50000 0003F000 C:\WINDOWS\system32\mswsock. dll
16 : 71A90000 00008000 C:\WINDOWS\System32\wshtcpip. dll
17 : 71AA0000 00008000 C:\WINDOWS\system32\WS2HELP. dll
18 : 71AB0000 00017000 C:\WINDOWS\system32\WS2_32. dll
19 : 72D10000 00008000 C:\WINDOWS\system32\msacm32. drv
20 : 72D20000 00009000 C:\WINDOWS\system32\wdmaud. drv
21 : 73DD0000 000FE000 C:\WINDOWS\system32\MFC42. DLL
22 : 74720000 0004B000 C:\WINDOWS\system32\MSCTF. dll
23 : 751D0000 0001E000 C:\WINDOWS\system32\wshbth. dll
24 : 76380000 00005000 C:\WINDOWS\system32\MSIMG32. dll
25 : 763B0000 00049000 C:\WINDOWS\system32\comdlg32. dll
26 : 76B40000 0002D000 C:\WINDOWS\system32\WINMM. dll
27 : 76C30000 0002E000 C:\WINDOWS\system32\WINTRUST. dll
28 : 76C90000 00028000 C:\WINDOWS\system32\IMAGEHLP. dll
29 : 76F20000 00027000 C:\WINDOWS\system32\DNSAPI. dll
30 : 76F60000 0002C000 C:\WINDOWS\system32\WLDAP32. dll
31 : 76FB0000 00008000 C:\WINDOWS\System32\winrnr. dll
32 : 76FC0000 00006000 C:\WINDOWS\system32\rasadhlp. dll
33 : 76FD0000 0007F000 C:\WINDOWS\system32\CLBCATQ. DLL
34 : 77050000 000C5000 C:\WINDOWS\system32\COMRes. dll
35 : 77120000 0008C000 C:\WINDOWS\system32\OLEAUT32. dll
36 : 773D0000 00103000 C:\WINDOWS\WinSxS\x86_Microsoft. Windows. Common-Controls_6595b64144ccf1df_6. 0.2600.2982_x-ww_ac3f9c03\comctl32.dll
37 : 774E0000 0013D000 C:\WINDOWS\system32\ole32. dll
38 : 77920000 000F3000 C:\WINDOWS\system32\SETUPAPI. dll
39 : 77A80000 00094000 C:\WINDOWS\system32\CRYPT32. dll
40 : 77B20000 00012000 C:\WINDOWS\system32\MSASN1. dll
41 : 77B40000 00022000 C:\WINDOWS\system32\Apphelp. dll
42 : 77BD0000 00007000 C:\WINDOWS\system32\midimap. dll
43 : 77BE0000 00015000 C:\WINDOWS\system32\MSACM32. dll
44 : 77C00000 00008000 C:\WINDOWS\system32\VERSION. dll
45 : 77C10000 00058000 C:\WINDOWS\system32\msvcrt. dll
46 : 77DD0000 0009B000 C:\WINDOWS\system32\ADVAPI32. dll
47 : 77E70000 00091000 C:\WINDOWS\system32\RPCRT4. dll
48 : 77F10000 00047000 C:\WINDOWS\system32\GDI32. dll
49 : 77F60000 00076000 C:\WINDOWS\system32\SHLWAPI. dll
50 : 77FE0000 00011000 C:\WINDOWS\system32\Secur32. dll
51 : 78130000 0009B000 C:\WINDOWS\WinSxS\x86_Microsoft. VC80. CRT_1fc8b3b9a1e18e3b_8. 0.50727.42_x-ww_0de06acd\MSVCR80.dll
52 : 79000000 00045000 C:\WINDOWS\system32\mscoree. dll
53 : 79060000 00053000 C:\WINDOWS\Microsoft. NET\Framework\v2. 0.50727\mscorjit. dll
54 : 790C0000 00AE8000 C:\WINDOWS\assembly\NativeImages_v2. 0.50727_32\mscorlib\b7467c3b3405254fa2bca974ea8c779b\mscorlib. ni.dll
55 : 79E70000 00561000 C:\WINDOWS\Microsoft. NET\Framework\v2. 0.50727\mscorwks. dll
56 : 7A440000 007BE000 C:\WINDOWS\assembly\NativeImages_v2. 0.50727_32\System\83f1a4489488354ea48a312721703189\System. ni.dll
57 : 7C800000 000F4000 C:\WINDOWS\system32\kernel32. dll
58 : 7C900000 000B0000 C:\WINDOWS\system32\ntdll. dll
59 : 7C9C0000 00815000 C:\WINDOWS\system32\SHELL32. dll
60 : 7E1E0000 000A0000 C:\WINDOWS\system32\urlmon. dll
61 : 7E410000 00090000 C:\WINDOWS\system32\USER32. DLL

Call stack :
7C812A09:0052 [7C812A5B] RaiseException [C:\WINDOWS\system32\kernel32. dll]
79F938BC:37A9 [79F97065] GetCLRFunction [C:\WINDOWS\Microsoft. NET\Framework\v2. 0.50727\mscorwks.dll]
7A05116B:A7D7 [7A05B942] ClearDownloadCache [C:\WINDOWS\Microsoft. NET\Framework\v2. 0.50727\mscorwks.dll]
7A05116B:A880 [7A05B9EB] ClearDownloadCache [C:\WINDOWS\Microsoft. NET\Framework\v2. 0.50727\mscorwks.dll]
7A05116B:A88B [7A05B9F6] ClearDownloadCache [C:\WINDOWS\Microsoft. NET\Framework\v2. 0.50727\mscorwks.dll]
79E92B84:3C0D [79E96791] NGenCreateNGenWorker [C:\WINDOWS\Microsoft. NET\Framework\v2. 0.50727\mscorwks.dll]
79E73820:0EEB [79E7470B] GetCompileInfo [C:\WINDOWS\Microsoft. NET\Framework\v2. 0.50727\mscorwks.dll]
 

perez,have you found the way?

can we communicate with each other?

my msn:pang2042@hotmail.com

or send email to:pang2042@163.com

 
Well. It has been 2009. Any solution for this issue? Thanks!
 
pisceswzh:
Well. It has been 2009. Any solution for this issue? Thanks!

I wrote a guide at http://disorderly-conductor.spaces.live.com . If you are looking to do your own, my instructions will be pretty ez to follow, but if you can't, I can help you for $$$

 
perez wrote >>
Does anyone know if it is possible to call a managed dll file developed in say c# from mq4 code. I have seen examples on how to call functions from mq4 to that live inside of unmanged code developed in C++ dll files. Anyway, any examples of how to go about doing this would be great using mq4 and visual studio 2005.

Marty

new MetaTrader .NET API from Amplefile

http://www.dotnetremoting.com/dow.aspx

enquires : support@dotnetremoting.com

Reason: