Call a secondary encapsulated DLL in MT4, but with no results?!!

Back to topics list To post a new topic, please log in or register
avatar
54
saji 2016.09.09 12:15
 
GUYs:

By "secondary encapsulated DLL", I mean I build a B.dll, which calls A.dll. I don't know the exactly tech name of that.....

But when I call this B.dll, the MT4 doesn't do anything at all, and there's no error msgs in the log file.

Here's the codes.

I first build a helloworldDLL.dll which simply just create a txt in d:\, and write the system time and a "Hello, World!" into it.

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <iostream>

using namespace std;

extern "C" __declspec(dllexport) void HelloWorld();

void HelloWorld()
{
        //----
        FILE *fp = NULL;
        //----
        char tmp[64];
        time_t t = time(0);
        strftime(tmp, 64, "%Y/%m/%d/%X", localtime(&t));
        //----
        fp = fopen("d:\\test.txt","w");
        fprintf(fp, "%s\n", tmp);
        fprintf(fp, "Hello,World!\n");
        return;
}

Then, I build a Callhelloworld.dll which call the HelloWorld() to do the samething:

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <iostream>

using namespace std;
extern "C" __declspec(dllimport) void HelloWorld();
extern "C" __declspec(dllexport) void CallHelloWorld();

void CallHelloWorld()
{
        HelloWorld();
        return;
}

After that, I use the below script to call the "secondary encapsulated DLL"----Callhelloworld.dll in MT4:

//----------
#import "Callhelloworld.dll"
 void CallHelloWorld();
#import

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{
   CallHelloWorld();
   return(0);
}
//+------------------------------------------------------------------+

but, there's no results in d:\. Also no error msg in log-files.

I have successfully call the helloworldDLL.dll directly in MT4.

So my question is:

1. Is Mt4 allowed to use the so-called "secondary encapsulated DLL"?

2. If the answer is yes, then how should I do it?

Below is the additional informations:

1. I use a MetaTrader 4 4.00 build 409 in a 32-bit Win7 system;

2. I put the helloworldDLL.dll/lib and Callhelloworld.dll all in ...\experts\libraries\;

If you need other information to find out my mistakes, pls ask!

Thank you in Advanced!

saji


avatar
1316
jjc 2016.09.09 13:36 #
 
saji:

1. I use a MetaTrader 4 4.00 build 409 in a 32-bit Win7 system;

Build 409? That's nearly 5 years old and should no longer be able to connect to an MT4 Server.

What you are describing works for me in build 1012: MT4 calling one DLL which calls another DLL. The two DLL files need to be present in MQL4\Libraries (or on the system path). The .lib file is not required.

I suggest that you do a test which does not involve MT4. Try creating a mini test application which does the same thing as MT4: load Callhelloworld.dll using LoadLibrary() and then call the  CallHelloWorld() function using GetProcAddress(). If that doesn't work, then the problem lies with your DLLs, not with anything to do with MT4.

You can also use something like the Dependency Walker to check the DLL imports/exports, and that Callhelloworld.dll is able to link to helloworldDLL.dll.

avatar
54
saji 2016.09.09 16:43 #
 
jjc:

Build 409? That's nearly 5 years old and should no longer be able to connect to an MT4 Server.

What you are describing works for me in build 1012: MT4 calling one DLL which calls another DLL. The two DLL files need to be present in MQL4\Libraries (or on the system path). The .lib file is not required.

I suggest that you do a test which does not involve MT4. Try creating a mini test application which does the same thing as MT4: load Callhelloworld.dll using LoadLibrary() and then call the  CallHelloWorld() function using GetProcAddress(). If that doesn't work, then the problem lies with your DLLs, not with anything to do with MT4.

You can also use something like the Dependency Walker to check the DLL imports/exports, and that Callhelloworld.dll is able to link to helloworldDLL.dll.

Thank you for your reply, and reply so fast...

1. I did do the test which not involving MT4 to call the Callhelloworld.dll, I created a console app to do that, and it works just fine!

2. The reason I use v409 is because it's structure is almost clear to users, which we can do some advanced work like tickdata backtesting, modify the .raw/.sel files(so we can add custom symbols into charts), and so on...

    And I use this version to connected to local markets(financial futures and stock markets in China) through .dll which will provide the both data-communication and trading-channel directly from the Exchanges (not from brokers).

    But the official .dll from local Exchanges is built with c++, which has a lot of pointers and class/structure in it. These things are not supported by MT4 v409. So I have to build a middle .dll to deal with those things.

    If v409 cannot support calling dll which also use another dll, then it's a real problem to me.

3. I will continue the testing with MT4, but using LoadLibrary() and  GetProcAddress()......instead of dllexport/import in Callhelloworld.dll to see the differrence.

eh...still a lot of works to do!

But still thank you for your help!

avatar
1316
jjc 2016.09.09 16:49 #
 
saji:

1. I did do the test which not involving MT4 to call the Callhelloworld.dll, I created a console app to do that, and it works just fine!

If the console app is dynamically linked to Callhelloworld.dll, using LoadLibrary() and GetProcAddress() instead of being statically linked, then it should be replicating what MT4 does.

I would expect any version of MT4, however old, to support what you are trying to do. It is just possible, but unlikely, that on older builds the helloworld.dll needs to be in the system path rather than in experts\libraries. But that seems unlikely. 

avatar
54
saji 2016.09.11 15:41 #
 
jjc:

I would expect any version of MT4, however old, to support what you are trying to do. It is just possible, but unlikely, that on older builds the helloworld.dll needs to be in the system path rather than in experts\libraries. But that seems unlikely. 

Hi, jjc:

it seems that your "unlikely" possibility is the final correct answe!!! :)

I use the same callhelloworld.dll in experts\library\, and put the helloworldDLL.dll in the ...\system32\, and the dll is successfully been called!



Note that, in the before failure calling, the dll confirm window never appears...

Also I still don't know the exactly reason for this, but it works.

And finally, my work can continue.

Really thanks to you, jjc!

saji

Back to topics list  

To add comments, please log in or register