Alright, I know everyone is thinking, "This has already been answered several times." Well, you are wrong. This time is different. I have tried all of those other answers. So here is the situation.
I am creating an indicator in Metatrader 4 (mql4 code). I am coding a dll to do the calculations in Visual Studio 2013 in C++.
The relevant MQL4
#import
code is:
#import "test.dll"
bool LiveChart( BarTrack &bars,
Stars &points,
Patterns &gartleys[],
Patterns &bats[],
Patterns &butterflies[],
Patterns &cyphers[],
BarData &rates[],
Basics &basics
);
#import
and the call to the function in the OnCalculate()
function:
bool test = LiveChart( bars,
points,
gartleys,
bats,
butterflies,
cyphers,
rates,
basics
);
Print( "test: ", test );
NOTE: All the passed arguments are struct
-references. None of the structs contain objects, pointers, references, strings, other structs, classes, methods, or arrays. Some of the structs are arrays, but that is entirely valid as a passed argument. So, there are NO invalid arguments being passed. I have verified that each struct
passes successfully, on an individual basis.
Now the C++ code:
#define WIN32_LEAN_AND_MEAN
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#define MT4_EXPFUNC __declspec(dllexport)
MT4_EXPFUNC bool __stdcall LiveChart(const BarTrack &bars, Stars &points, Patterns *gartleys, Patterns *bats,
Patterns *butterflies, Patterns *cyphers, const BarData *rates, Basics &basics)
{
Observatory astronomer;
return astronomer.OnCalculateLive(bars, points, gartleys, bats, butterflies, cyphers, rates, basics);
}
NOTE: I have also tried:
extern "C"
{
MT4_EXPFUNC bool __stdcall LiveChart(const BarTrack &bars, Stars &points, Patterns *gartleys, Patterns *bats,
Patterns *butterflies, Patterns *cyphers, const BarData *rates, Basics &basics)
{
Observatory astronomer;
return astronomer.OnCalculateLive(bars, points, gartleys, bats, butterflies, cyphers, rates, basics);
}
}
In my def file:
LIBRARY test
EXPORTS
LiveChart
I have reviewed the code with the Dependency Walker program. It tells me the name of the function is:
bool LiveChart(struct BarTrack const &,struct Stars &,struct Patterns *,struct Patterns *,struct Patterns *,struct Patterns *,struct BarData const *,struct Basics &)
As far as I understand, everything is as it should be.
My question is,
why does metatrader still say it cannot find the function name in the dll?
Have I overlooked something?
Am I using the wrong type of voodoo?
Are the stars not aligned properly?
Admittedly, I am still pretty new to C++ (about a month into it), but as far as can tell, everything is kosher, and it should work.
Finally! I have come to a resolution with this issue. The issue was, the def file became unlinked to the project. Here is what happened.
When starting a new dll project, VS creates a dllmain.cpp file with the main function in it. I don't like having this extra file in the project, so I prefer to move the main function into my project.cpp file. When I do this, I remove the dllmain.cpp file from the project. Apparently, if you have already linked your def file before you remove the dllmain.cpp, it will unlink your def file. I never even thought to recheck this because I knew I had already linked the def file correctly.
To fix the issue, all I had to do was select the project.cpp file, and go into the Project/Properties menu, and relink the def file. Now, I can finally start debugging.....