Creating DLLs in Visual Studio (17,19,22) in 2022

 
Hello,

I am trying to understand the workflow for building DLLs for MQL to use external Cpp structures, functions and classes in Mql5 code.

It seems things have changed since the following articles:

A DLL FOR MQL5 IN 10 MINUTES (PART II): CREATING WITH VISUAL STUDIO 2017


When I set up a new DLL project (with exports) in VS2017, the project does not import “stdafx.h” or use the ‘extern “C” ‘ convention.





The article suggests I have to update the Visual Studio template to have 'extern "C"'. When I add 'extern "C"' to the code, I get a bunch of build errors. I noticed the project does not incude "stdfx.h"




If I do not add 'extern "C"', I am able to build the DLL in Visual Studio. But when I try to use it in MT5, I receive the typical error:


You'll notice I tried to change the path to the DLL library since I did not save it in the root "Libraries" folder. Neither way worked.

Is the issue around using extern c and stdafx.h or what do I need to do differently to get the library to work in MT5? The only headers that are imported into the DLL project in Visual Studio when starting a new DLL project 'with Exports' are 

"pch.h"

"framework.h"


The Visual Studio DLL project With Exports files are pretty much the same between Visual Studio 2017 and Visual Studio 2022 (installed/updated as of today) and I would prefer to use Visual Studio 2022. So I think some things have changed. Either I need to find and include "stdafx.h" and add #pragma once and the other headers from the article. Or I'm missing something in my existing DLL code that would allow it to work in MQL5. Let me know if you need me to attach any files.

Can anyone with DLL building experience please provide some guidance? 

How to Exchange Data: A DLL for MQL5 in 10 Minutes
How to Exchange Data: A DLL for MQL5 in 10 Minutes
  • www.mql5.com
Now not so many developers remember how to write a simple DLL, and what are special features of different system binding. Using several examples, I will try to show the entire process of the simple DLL's creation in 10 minutes, as well as to discuss some technical details of our binding implementation. I will show the step-by-step process of DLL creation in Visual Studio with examples of exchanging different types of variables (numbers, arrays, strings, etc.). Besides I will explain how to protect your client terminal from crashes in custom DLLs.
 
Josh:
Hello,

I am trying to understand the workflow for building DLLs for MQL to use external Cpp structures, functions and classes in Mql5 code.

It seems things have changed since the following articles:

A DLL FOR MQL5 IN 10 MINUTES (PART II): CREATING WITH VISUAL STUDIO 2017


When I set up a new DLL project (with exports) in VS2017, the project does not import “stdafx.h” or use the ‘extern “C” ‘ convention.





The article suggests I have to update the Visual Studio template to have 'extern "C"'. When I add 'extern "C"' to the code, I get a bunch of build errors. I noticed the project does not incude "stdfx.h"




If I do not add 'extern "C"', I am able to build the DLL in Visual Studio. But when I try to use it in MT5, I receive the typical error:


You'll notice I tried to change the path to the DLL library since I did not save it in the root "Libraries" folder. Neither way worked.

Is the issue around using extern c and stdafx.h or what do I need to do differently to get the library to work in MT5? The only headers that are imported into the DLL project in Visual Studio when starting a new DLL project 'with Exports' are 

"pch.h"

"framework.h"


The Visual Studio DLL project With Exports files are pretty much the same between Visual Studio 2017 and Visual Studio 2022 (installed/updated as of today) and I would prefer to use Visual Studio 2022. So I think some things have changed. Either I need to find and include "stdafx.h" and add #pragma once and the other headers from the article. Or I'm missing something in my existing DLL code that would allow it to work in MQL5. Let me know if you need me to attach any files.

Can anyone with DLL building experience please provide some guidance? 

I was able to get this working by changing the build to Release x64. I think it has more to do with the x64 part, than release? I'm not sure. Would still like clarification on that if possible. Also, I still want to understand what needs to be included for the DLL to work, vs what doesn't. Please leave a reply! Thanks!

Reason: