Simple DLL leads to access violation errors

 

Hello community, this is my first topic.

 I am trying to build my own DLL for Metatrader 5 using C++ and Microsoft Visual Studio Community 2013.
I just coded this simple function here:

 

#include <string>


using namespace std;


#define _DLLAPI extern "C" __declspec(dllexport)


_DLLAPI string __stdcall test() {

return "test";

}

 And exported it as a .DLL file. When I want to import it to use it in my EA, I end up getting weird errors like this: 

2015.03.12 15:21:13.761 JavaBridge (EURUSD,H1) Access violation at 0x000007FEFB071276 write to 0x0000000000000018 in 'C:\...\MetaTraderTest.dll'

2015.03.12 15:21:13.771 JavaBridge (EURUSD,H1)   crash -->  000007FEFB071276 48C741180F000000  mov        qword [rcx+0x18], 0xf

Do you have a solution? I tried Google but it didn't help.

Thank you in advance!

Chris 


 
cxan_96:

Hello community, this is my first topic.

 I am trying to build my own DLL for Metatrader 5 using C++ and Microsoft Visual Studio Community 2013.
I just coded this simple function here:

 

#include <string>


using namespace std;


#define _DLLAPI extern "C" __declspec(dllexport)


_DLLAPI string __stdcall test() {

return "test";

}

 And exported it as a .DLL file. When I want to import it to use it in my EA, I end up getting weird errors like this: 

2015.03.12 15:21:13.761 JavaBridge (EURUSD,H1) Access violation at 0x000007FEFB071276 write to 0x0000000000000018 in 'C:\...\MetaTraderTest.dll'

2015.03.12 15:21:13.771 JavaBridge (EURUSD,H1)   crash -->  000007FEFB071276 48C741180F000000  mov        qword [rcx+0x18], 0xf

Do you have a solution? I tried Google but it didn't help.

Thank you in advance!

Chris 


What version of MetaTrader do you use (32-bit or 64-bit)? Can you send MetaTraderTest.dll?
 
forex_trader:
What version of MetaTrader do you use (32-bit or 64-bit)? Can you send MetaTraderTest.dll?

First: Thank you for your help, I appreciate it very much!

I am currently using Metatrader 5 Version 5.00 Build 1085 64-bit and I will attach the .dll file. 

Greetings

Chris 

In case the Attach file option does not work:

https://dl.dropboxusercontent.com/u/34688380/MetaTraderTest.dll 

 
cxan_96:

First: Thank you for your help, I appreciate it very much!

I am currently using Metatrader 5 Version 5.00 Build 1085 64-bit and I will attach the .dll file. 

Greetings

Chris 

In case the Attach file option does not work:

https://dl.dropboxusercontent.com/u/34688380/MetaTraderTest.dll 

You can't return a string this way.

https://www.mql5.com/en/forum/7386

 

Function test() should return wchar_t* value instead of string:

extern "C" __declspec(dllexport) wchar_t* __stdcall test()
{
 return (L"test");
} 
Reason: