I am trying to create my own DLL with DEV-C++ IDE tool and trying to use it inside MT4 script. I tried to study the example file [MT4_HOME]\MQL4\Scripts\Examples\DLL\DLLSample.cpp available in any MT4 installation and I tried to follow the same logic with other script but without sucess. Below I am describing in great details steps i followed just to be clear. I would like to understand why following the described steps my own dll doesn't work.
System configuration
- Laptop with windows 10 ;
- Dev- cpp installed
- MT4 installed
Goals
- to write my own dll by using "dev–c++" IDE tool;
- compile the dll;
- use the dll into a simple script in mt4.
Steps
- First I create a folder on my desktop named mydll;
- I start dev-cpp IDE tool;
- File -> New -> Project;
- I select project type -> DLL
- I write project name: mydll
- I press OK button
- Then I choose the folder in which to save the project (the folder mydll created in desktop at step a) and press save
- At this point Dev –C++ showes me two file templates (dllmain.cpp, dll.h) but I ignore them and close them without saving them into the project. After closing them I also remove them from IDE tool (write click with mouse and click remove file for each of them)
- Now I rigth clik over devc++ project -> New File
- Now I paste into this file the source code of my own DLL. (the below code) Note: For people who are familiar with metatrader 4, please notice that this code is a fragment of the file [MT4_HOME]\MQL4\Scripts\Examples\DLL\DLLSample.cpp of standard MT4 installation
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
//---
#define MT4_EXPFUNC __declspec(dllexport)
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{
//---
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
//---
return(TRUE);
}
MT4_EXPFUNC int __stdcall GetIntValue(const int ipar)
{
printf("GetIntValue takes %d\n",ipar);
return(ipar);
}
- I save this file into my DEV-C++ project folder with name mydll.cpp
- Now, in DEV-C++ ide tool I press F9 button to compile this file.
- Observations: a. the compilation process completes succesfully without any errors and any warnings b. some files appears into the DEV-C++ project (mydll.dll, libmydll.def, libmydll.a, mydll.o, Makefile.win, mydll.layout).
- Now, I copy and paste the mydll.dll into [MT4_HOME]\MQL4\Libraries directory of MT4
- Now, I create an empty folder [MT4_HOME]\MQL4\Scripts\Examples\mydll
- I copy and paste the files mydll.cpp and libmydll.def into the [MT4_HOME]\MQL4\Scripts\Examples\mydll folder
- Finally, I create a new file named mydllTester.mq4 into the [MT4_HOME]\MQL4\Scripts\Examples\mydll folder. Below is the source code
#import "DLLTutorial.dll"
int _Z11GetIntValuei(int);
#import
void OnStart()
{
int cnt=_Z11GetIntValuei(int(10));
Comment(cnt);
}
- I open the file mydllTester.mq4 with the MT4 code editor and I compile the file.
- Final test As the final step, I make a test to check if this works. I open Metatrader4 , I open a new chart and I simply click over my script . My expectation is that the number 10 appears on the top left bottom of the chart buti t doesn’t work. Can you help me to understand which is the step I am making mistakes? Thank you very much, Best Regards