Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
I sent Codersguru a pm with a similar request, but figured it would be something that would be useful for the whole community. Also, he seems like a busy guy, so I'm hoping that maybe someone else out there might also have the answer:
Here is the problem...I am trying to write a .dll in C++ using VS 2005 to connect to MT4. I have read through Codersguru's tutorial, but I have had no luck compiling and implementing his .dll, which is strange because I've been able to compile my own .dll's (I'm sure this is something small as far as the compile goes...his pre-compiled dll-utilizing projects work for me just fine). I have also been able to compile the sample .dll provided by metaquotes, but I've had zero luck in using it. The problem, I believe, is the fact that I have been using VS 2005 and that the tutorial and sample dll are a bit dated. What I really would like to have is a very clear, step-by-step, set of instructions and sample code to compile a .dll in VS 2005 and then call it from MT4. Think in terms of explaining it to someone with almost no experience with VS 2005 C++ (the compiler and I don't get along very well.) Also, I would like to be able to use the .NET library, so this probably provides another wrinkle. My impression is that MT4 is not compatible with managed code. I have looked far and wide on the internet to find a solution to this, and have found many many resources....which all seem to be 3-6 years out of date...resulting in the same problem..."How the %&**&% do I do that in Visual Studio 2005!"
I have been working on my larger problem for about 5 weeks now, and I'm starting to get tired. I've got most of the issues worked out, but this last part, "connecting" MT4 to .NET has been the thorn in my foot for quite some time. Any help would be greatly appreciated.
Also, I intend to release some of my implementations to the public domain...for example, a "one-click" trading interface for day-traders (incorporating brackets, trailing stops, OCO, and other goodies). I intend to do most of my programming in the much friendlier language of C#, but this part needs to be addressed in C++ it seems.
Again, any help would be appreciated...a sample with instructions on how to compile in VS 2005 would probably do the trick. Thank you.
From what I understand, and my MetaTrader dlls have only been developed in either MingW or Visual C++ 7.1, the interface into the dll should not be managed. Couldn't you have a dll that is not managed access managed code in a second dll?
Not sure how technical you are, but the following explains how to call managed from native (which is what you will need to do):
Thank you very much for the reply. I'm technical enough. Frankly, the link that you provided is probably one of the most straightforward and simple explanations of interop on the internet. I'm going to have to try this out, as this looks almost exactly like what I'm looking for (I'll know for sure after I dig into it more).
Another possible solution to the problem is using sockets to accomplish the interop.
Another question: Have you had success using your .dll's in MT4? Maybe I just need to switch compilers, but I haven't had success with VS 2005 compiled dll's (not in connecting to MT4). I probably will also try Bloodshed, which I guess uses mingW. I'll say this, though, the VS 2005 Express Edition compiler is a pain in the you know where, at least for C++...almost nothing seems to work.
Thanks for your help...if I have another question, could I pm you?
I've built dlls with Visual Studio 2005 that work with MT4 so I know it can be done.
I do remember running into problems like this, but don't remember the solutions. Some things to check are:
Check the .def file and make sure it exports correctly, and that it's included in the 2005 Solution.
Make sure all the exported functions are declared with __declspec(dllexport) and ___stdcall.
If that doesn't help PM me and I'll take a look at your projects.
Using CodeBlocks (www.codeblocks.org) and MinGW, I was able to compile dlls that worked fine in MT4. I am now testing out the VC++ 7.1 compiler to see if it works as well.
I couldn't get it to work...so I guess the answer is 'no.'
But I think the main problem was the Visual Studio C++ compiler. Frankly, I think it's a piece of junk. I've set it up according to the instructions at MSDN and double-checked and I'm always having problems with it. Others have similar problems to the ones I have.
I don't have these problems with the C# or VB compilers.
Also, just fyi, I've done a similar process before calling a C# compiled COM object from VB and I didn't have a problem. Of course, that doesn't really help here, because of MQL.
I tried adding the .def file to the .dll and that didn't work. I've only tried this in Visual Studio so far. I haven't tried it with mingw yet. I'd really like to be able to cross the managed code to unamanaged code boundary, though.