Hello, I have a Dynamic Link library project in code blocks. I want my EA to import functions from the codeblocks DLL project. I was reading the documentation on Importing Function (#import), and tried to follow it closely. It says that "MQL5 libraries are loaded from the terminal_dir\MQL5\Libraries folder." I tried to copy and paste the .dll file into this directory, so that importing functions could be possible. However, I could not find this directory anywhere!! I searched in lots of places. For example, searched in C:\Program Files\MetaTrader 5\MQL5, and all over my C drive. My friend installed metatrader 5 and could not find it either, does anyone else have this same problem?? I tried pasting the .dll file in terminal_installation_directory\MQL5\Include, but this didn't work. The EA compiles fine, but when attached to a chart, it says the initialization failed and the expert is removed. Does anyone have any ideas on how to make the DLL work? Here is my code
1. When posting code in forum, please use SRC button, it makes your code much easier to read for other user who wants to help you
2. I bet you also don't know where yor EA, CI, and script is located. Use TerminalInfoString's TERMINAL_DATA_PATH, and if you use Vista/7, you'll find it in C:\Users\<use name>\AppData\Roaming\MetaQuotes\Terminal\<unix code>
3. Read this also How to Exchange Data: A DLL for MQL5 in 10 minutes.
Hello, I have a Dynamic Link library project in code blocks. I want my EA to import functions from the codeblocks DLL project. I was reading the documentation on Importing Function (#import), and tried to follow it closely. It says that "MQL5 libraries are loaded from the terminal_dir\MQL5\Libraries folder." I tried to copy and paste the .dll file into this directory, so that importing functions could be possible. However, I could not find this directory anywhere!! I searched in lots of places. For example, searched in C:\Program Files\MetaTrader 5\MQL5, and all over my C drive. My friend installed metatrader 5 and could not find it either, does anyone else have this same problem?? I tried pasting the .dll file in terminal_installation_directory\MQL5\Include, but this didn't work. The EA compiles fine, but when attached to a chart, it says the initialization failed and the expert is removed. Does anyone have any ideas on how to make the DLL work? Here is my code
DLL in codeblocks
main.h
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void DLL_EXPORT SomeFunction(const LPCSTR sometext);
void DLL_EXPORT PrintInt(int someint);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
main.cpp
#include "main.h"
#include <iostream>
using namespace std;
// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}
void DLL_EXPORT PrintInt(int someint)
{
cout << someint << "\n";
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
Calling_C++ EA
//+------------------------------------------------------------------+
//| Calling_C++.mq5 |
//| Derek & Joe |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Derek & Joe"
#property link "http://www.mql5.com"
#property version "1.00"
#import "mql5_DLL.dll"
void PrintInt(int someint);
#import
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
int cmon=3;
PrintInt(cmon);
//---
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
MqlRates rt[2];
//--- call the Evolved Trader application only for first ticks of new bar
if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
{
Print("CopyRates of ",_Symbol," failed, no history");
return;
}
if(rt[1].tick_volume>1) return;
}
//+------------------------------------------------------------------+