Skip to content
All library documents

Building and Connecting C++ DLLs for MetaTrader 5

Article MQL5 articles

Summary

This beginner guide walks through building a C++ dynamic library in Visual Studio 2017 and connecting it to MetaTrader. It covers project setup, Unicode configuration, copying the build output into the terminal’s library folder, and exporting functions with undecorated names through either C linkage or a module definition file. It also demonstrates a simple exported function and initialization through DllMain, then describes calling library functions from MQL5.

The guide notes that MetaTrader 5 requires 64-bit DLLs, while MetaTrader 4 requires 32-bit DLLs. DLLs can add capabilities or improve performance for tasks such as parsing HTML, but they introduce deployment and security concerns and make the trading application dependent on the library. The examples show a function returning a value initialized at process attachment and report that thread-attachment initialization is not triggered as expected. The article is a software integration tutorial, not a trading strategy, and its examples are tied to an older Visual Studio release; readers should verify current platform and toolchain details.

Key ideas

  • MetaTrader 5 requires 64-bit libraries, whereas MetaTrader 4 accepts 32-bit libraries.
  • Exported C++ function names can be kept compatible with MQL imports by using C linkage or a module definition file.
  • Visual Studio post-build events can copy a completed library into the terminal’s library folder.
  • DLLs can provide functions or performance that MQL may not offer, but they add deployment and security risks.
  • The example warns that DllMain thread-attachment behavior may differ from a developer’s expectations.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.