
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Dear,
I program in VS 2010. I created two project:
one of projects is C#(named MT4TestDLL), the other one is C++ (choose CLR in Project Type) (named CallTest)
The EA of MT4 will call the C++ and C++ create an object that wrote with C#. When I execute this, I always receive error message like this " funcion 'xxx' call from 'yyy.dll' critical error "
Anyone know how to solve it?
C++ Project Codes
1. Reference MT4TestDLL
2. Codes
#include "stdafx.h"
#include <vcclr.h>
#include <stdlib.h>
#include <string.h>
#include "MM_Connector.h"
using namespace MT4TestDLL;
extern "C"
{
__declspec(dllexport) char* __stdcall whatABC();
}
__declspec(dllexport) char* __stdcall whatABC()
{
clsMyTest ^obj = gcnew clsMyTest();
// Convert System::String ^ to Char *
pin_ptr<const wchar_t> wch = PtrToStringChars(obj->getAbc());
size_t origsize = wcslen(wch) + 1;
const size_t newsize = origsize*2;
size_t convertedChars = 0;
char *nstring = new char[newsize];
wcstombs_s(&convertedChars, nstring, newsize, wch, _TRUNCATE);
return nstring;
}
3. set the CallTest.def
LIBRARY CallTest
EXPORTS
whatABC
C# Project Codes
1. Codes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MT4TestDLL
{
public class clsMyTest
{
string abc;
public clsMyTest()
{
abc = "clsMyTest constructor";
}
public string getAbc()
{
return abc;
}
}
}