when link to C# dll from EA, there has been a critical error

 

I have some method at C# dll, so i think to call C# dll from MT4 EA, but don't know how to do it.
now i do it other in another way.
1.I created C++ dll,then from this dll to call C# dll,i think it is ok,because i can get the result from a test application used the same code.
2.I call this C++dll from mt4 EA, when i commented the code calling C# dll, it works fine.
3.now i am from MT4 EA to call C# dll through C++ dll,
there has been a criticall error...

******************************************************
Registers : EAX=02BEF19C CS=001b EIP=7C81EB33 EFLGS=00000202
: EBX=001B1838 SS=0023 ESP=02BEF198 EBP=02BEF1EC
: ECX=00000000 DS=0023 ESI=02BEF228 FS=003b
: EDX=00000025 ES=0023 EDI=E0434F4D GS=0000

Stack Trace : 79F97065 79F972D0 7A0A129E 7906EF54
: 7906EBC0 7906E8DB 7906E831 79E9776F
: 79E976E5 79E9767A 79E97516 7C92EE18
: 7C92EE18 7C92EE18 7C92EE18 7C92EE18

Modules :
1 : 00400000 007F5194 c:\program files\metatrader\terminal.exe
2 : 02BF0000 00102000 c:\windows\winsxs\x86_microsoft.vc80.debugcrt_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcm80d.dll
3 : 0FFD0000 00028000 c:\windows\system32\rsaenh.dll
4 : 10000000 00016000 c:\program files\metatrader\experts\libraries\mt4analysic.dll
5 : 10200000 00120000 c:\windows\winsxs\x86_microsoft.vc80.debugcrt_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcr80d.dll
6 : 10480000 000FC000 c:\windows\winsxs\x86_microsoft.vc80.debugcrt_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c\msvcp80d.dll
7 : 20000000 00549000 c:\windows\system32\xpsp2res.dll
8 : 5AD70000 00038000 c:\windows\system32\uxtheme.dll
9 : 5E380000 00089000 c:\windows\microsoft.net\framework\v2.0.50727\diasymreader.dll
10 : 60FD0000 00055000 c:\windows\system32\hnetcfg.dll
11 : 61BE0000 0000D000 c:\windows\system32\mfc42loc.dll
12 : 62C20000 00009000 c:\windows\system32\lpk.dll
13 : 719C0000 0003E000 c:\windows\system32\mswsock.dll
14 : 71A00000 00008000 c:\windows\system32\wshtcpip.dll
15 : 71A10000 00008000 c:\windows\system32\ws2help.dll
16 : 71A20000 00017000 c:\windows\system32\ws2_32.dll
17 : 72C80000 00008000 c:\windows\system32\msacm32.drv
18 : 72C90000 00009000 c:\windows\system32\wdmaud.drv
19 : 73640000 0002E000 c:\windows\system32\msctfime.ime
20 : 73D30000 000FE000 c:\windows\system32\mfc42.dll
21 : 73FA0000 0006B000 c:\windows\system32\usp10.dll
22 : 74680000 0004B000 c:\windows\system32\msctf.dll
23 : 759D0000 000AE000 c:\windows\system32\userenv.dll
24 : 762F0000 00005000 c:\windows\system32\msimg32.dll
25 : 76300000 0001D000 c:\windows\system32\imm32.dll
26 : 76320000 00047000 c:\windows\system32\comdlg32.dll
27 : 765E0000 00092000 c:\windows\system32\crypt32.dll
28 : 76990000 0013D000 c:\windows\system32\ole32.dll
29 : 76B10000 0002A000 c:\windows\system32\winmm.dll
30 : 76C00000 0002E000 c:\windows\system32\wintrust.dll
31 : 76C60000 00028000 c:\windows\system32\imagehlp.dll
32 : 76DB0000 00012000 c:\windows\system32\msasn1.dll
33 : 770F0000 0008C000 c:\windows\system32\oleaut32.dll
34 : 77180000 00102000 c:\windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.2600.2180_x-ww_a84f1ff9\comctl32.dll
35 : 77BA0000 00007000 c:\windows\system32\midimap.dll
36 : 77BB0000 00015000 c:\windows\system32\msacm32.dll
37 : 77BE0000 00058000 c:\windows\system32\msvcrt.dll
38 : 77D10000 0008F000 c:\windows\system32\user32.dll
39 : 77DA0000 000A9000 c:\windows\system32\advapi32.dll
40 : 77E50000 00091000 c:\windows\system32\rpcrt4.dll
41 : 77EF0000 00047000 c:\windows\system32\gdi32.dll
42 : 77F40000 00076000 c:\windows\system32\shlwapi.dll
43 : 78130000 0009B000 c:\windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_0de06acd\msvcr80.dll
44 : 79000000 00045000 c:\windows\system32\mscoree.dll
45 : 79060000 00053000 c:\windows\microsoft.net\framework\v2.0.50727\mscorjit.dll
46 : 790C0000 00AE6000 c:\windows\assembly\nativeimages_v2.0.50727_32\mscorlib\62c98dd25f77b84d873edfcb7a274664\mscorlib.ni.dll
47 : 79E70000 00561000 c:\windows\microsoft.net\framework\v2.0.50727\mscorwks.dll
48 : 7A440000 007BE000 c:\windows\assembly\nativeimages_v2.0.50727_32\system\e0864aead013344fb1deec4bd6a1a959\system.ni.dll
49 : 7C800000 0011C000 c:\windows\system32\kernel32.dll
50 : 7C920000 00094000 c:\windows\system32\ntdll.dll
51 : 7D590000 007F2000 c:\windows\system32\shell32.dll

Call stack :
******************************************************
C++ dll

#using "C:\Program Files\MetaTrader\experts\libraries\MT4analysic2.dll"
using namespace MT4analysic;
#define MT4_EXPFUNC __declspec(dllexport)
BOOL APIENTRY _tmain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}

//----
return(TRUE);
}
MT4_EXPFUNC int __stdcall add1(int x,int y)
{
int aRet=5;
Mt4Proxy ^dllclass = gcnew Mt4Proxy();
aRet= dllclass->add(x,y);
int aRet1=5;
return aRet;
}

maybe someone can give me a answer,thanks to you

 

mq4 code to call c++ dll

#property copyright "Copyright ?2008,121sec Software Corp."
#property link "http://www.121sec.com"

#include <WinUser32.mqh>
#import "Mt4analysic.dll"
int add1(int,int);


#import
//---- input parameters
extern string user;
extern string password;

int startFlag=0;

int init()
{
return(0);
}
int deinit()
{
return(0);
}
int start()
{
if(startFlag==0){
startFlag=1;
int sRet=add1(1,3);
MessageBox("start function 0,startFlag= "+startFlag+",sret="+sRet,"Attention",MB_OK|MB_ICONWARNING);
}else{
int sRet1=add1(1,3);
string ha="haha";
MessageBox("start function 1,startFlag= "+startFlag+",sret1="+sRet1,"Attention",MB_OK|MB_ICONWARNING);
}
return(0);
}

 

C# dll code

namespace MT4analysic{

public class Mt4Proxy
{

public Mt4Proxy()
{
}

public int add(int x, int y) {
return x + y;
}

}

}