加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

[转载]【转帖】MetaTrader 4 (MT4) DLL编程(II)

(2012-08-04 16:20:07)
标签:

转载

分类: 交易系统
【转帖】MetaTrader 4 (MT4) DLL编程(II)

Create your own MetaTrader extension (dll) - Part 2

Hi folks!

In the previous part of this article we created step-by-step our first MetaTrader extension (dll) in C++ and in this article we are going to give it a test.

Also we are going to study in this article and the coming article some of the advanced topics briefly (like how to use arrays and structure in your dll).

Hope you are ready for this hard journey which deserves the effort.

Let's test our demo.dll

We are going to write some code to test our demo.dll. These are the steps we have to take before saying "Hello World!"

1- We have the demo.dll in the debug folder in your Visual C++ projects folder. Copy the demo.dll to the library folder ("MetaTrader 4expertslibraries").

2- Open MetaEditor to create the include file which will hold the declaration of our "Hello" function. This is the code of demo.mqh
 

#import "demo.dll"
void Hello(string say);
#import

Note how we have imported the dll and how we have declared the "Hello" function with the same parameters (string say) and return value (void) as the function in the dll.

This file will be saved at the Include folder (MetaTrader 4expertsinclude).

3- Now, let's create the script to test the demo.dll. We are going to name it "Hello.mq4" and it must be saved at the Scripts folder (MetaTrader 4expertsscripts).

#include <demo.mqh>

int start()
{
Hello ("Hello World!");
return(0);
}

Note how we have started the code by including the demo.mqh file to make it a part of our code.

4- Compile the script (F5) and load it now (double click it in the Navigator window in the Terminal). What did you get? a nice dialog like the one showed in figure 1, if not please check everything or email me!

http://s12/bmiddle/5090a7d1x77d34184462b&690(MT4) DLL编程(II)" TITLE="[转载]【转帖】MetaTrader (MT4) DLL编程(II)" />

Note: You have to enable the option "Allow DLL imports" in MetaTrader before using any code that import external functions (from the common windows dlls or you custom dlls like our demo.dll) that's by going to Tools -> Options -> Expert Advisors tab then checking "Allow DLL imports" (Figure 2).

http://s14/bmiddle/5090a7d1x77d31ea0bded&690(MT4) DLL编程(II)" TITLE="[转载]【转帖】MetaTrader (MT4) DLL编程(II)" />

Advanced Sample (ExpertSample)!

Our demo.dll was a simple one yet it was a completed dll. There's an advanced sample that shipped with MetaTrader program which include advanced programming topics. We are going to study it and thank MetaQuotes for its ideal sample.

You will find the sample of the dll in "MetaTrader 4EXPERTSSAMPLES"; the dll (ExpertSample.dll) in the folder "MetaTrader 4EXPERTSSAMPLESExpertSample", the include file (sampledll.mqh) in "MetaTrader 4EXPERTSSAMPLESINCLUDE" and the script (ExportFunctions.mq4) in "MetaTrader 4EXPERTSSAMPLES".

You have to open the source code of the dll (To open the source code double click ExpertSample.dsw file) and give the code a look. You will find it more advanced and to some degree a complex one compared to the demo.dll, but don't be afraid we are going to know everything in the next article.

from: http://www.metatrader.info/node/152

0

  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有