how to create dll for import in MT5 question

 

Hi guys i try to understund how  work dll  import in mt5  i use  this tutorial https://www.mql5.com/en/blogs/post/753426

i create a dll in VS 2022  c++ , dll ,with this code

BybitAPI.dll

#pragma once

#include "pch.h"
#include <utility>
#include <limits.h>

#ifdef BYBITAPIDLL_EXPORTS
#define BYBITAPIDLL_API __declspec(dllexport)
#else
#define BYBITAPIDLL_API __declspec(dllimport)
#endif

extern "C" BYBITAPIDLL_API int hard_math(int a, int b) {
    return a + b;
}

and create Test.mq5


#property version   "1.00"
#property strict
#import "BybitAPI.dll" 
int hard_math(int a,int b);
#import
int OnInit()
  {
  int result=hard_math(3,5);
  Print("DLL says "+IntegerToString(result));
  return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
  }

void OnTick()
  {
  }

but if in dll write

 {
    return a + b;
}

return me a function declared 'dllimport' may not be defined
'hard_math': definition of dllimport function not allowed  but if  i remove  workbut not  ofcourse return nothing , anyone know  why  ?

thanks

Create DLL , simplest form example
Create DLL , simplest form example
  • 2023.07.07
  • www.mql5.com
Hi!  First things first you need visual studio for this .  Install it , start it up
 

i try also in C#   but  unfortunately give me the  sam error ( more or less )

in my VS2022  i create a library dll in C#

using System;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;

public class MyClass
{
    [DllExport("AddNumbers", CallingConvention = CallingConvention.StdCall)]
    public static int AddNumbers(int a, int b)
    {
        return a + b;
    }
}

and  after  in mql5

#import "MyMQL5DLL.dll"
   int AddNumbers(int a, int b);
#import

void OnStart()
{
   int result = AddNumbers(5, 3);
   Print("The result is: ", result);
}

i try to insert dll in the same folder in the include folder and in library folder  but  always not find   a dll function  anyone have some idea?  thanks




2025.03.23 15:13:10.720    TEST (XRPUSD,M1)    cannot find 'int MyMQL5DLL::AddNumbers(int,int)' in module 'MyMQL5DLL.dll'
2025.03.23 15:13:10.721    TEST (XRPUSD,M1)    unresolved import function call in 'TEST.mq5' (1,1)