Metatrader 4 + C++ DLL? (Nézz be ha okosnak hiszed magad! )
Kezdésképpen ezt szeretném az MT-be behívni:
int addition (int a, int b) {
return (a+b);
}
A dll-t megcsinálom, depends-zel látom is benne a functiont, de az MT 126-os hibakóddal (module not found) nem hajlandó végrehajtani.
MT4 kód:
#import "Demo1.dll"
int addition(int a, int b);
#import
int init()
{
Print(addition(1, 1));
return(0);
}
Bocs a hangzatos címért :)





nem így kell dll-ből importálni....
"ez egy saját timer methódus c#-ban:
internal class HiPerfTimer
{
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceCounter(
out long lpPerformanceCount);
[DllImport("Kernel32.dll")]
private static extern bool QueryPerformanceFrequency(
out long lpFrequency);
private long startTime, stopTime;
private long freq;
// Constructor
public HiPerfTimer()
{
startTime = 0;
stopTime = 0;
if (QueryPerformanceFrequency(out freq) == false)
{
// high-performance counter not supported
throw new Win32Exception();
}
}
// Start the timer
public void Start()
{
// lets do the waiting threads there work
Thread.Sleep(0);
QueryPerformanceCounter(out startTime);
}
// Stop the timer
public void Stop()
{
QueryPerformanceCounter(out stopTime);
}
// Returns the duration of the timer (in seconds)
public double Duration
{
get
{
return (double)(stopTime - startTime) / (double)freq;
}
}
}
}
Igen:
#define DEMO1_API __declspec(dllexport)
DEMO1_API int addition(int a, int b) {
return (a+b);
}





Az #import -al csak typelib-et lehet használatba venni ha jól emléxem. Az olyasminek, amit te akarsz más módja van.
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
DWORD dwParam1;
UINT uParam2, uReturnVal;
hDLL = LoadLibrary("MyDLL");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,
"DLLFunc1");
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
return SOME_ERROR_CODE;
}
else
{
// call the function
uReturnVal = lpfnDllFunc1(dwParam1, uParam2);
}
}
Ezt úgy találtam, remélem sikerül megérteni...
Ma ráértem vele foglalkozni újból, leírom hogyan sikerült megcsinálni, hátha valaki még téved egyszer:
Demo.cpp:
#include "stdafx.h"
__declspec(dllexport) int Addition(int a, int b) {
return (a+b);
}
(az stdafx.h üres)
Kell egy Demo.def fájl:
LIBRARY Demo
EXPORTS Addition
Ezt a linkernél beállítani.
Az MQL4 kód:
#import "Demo.dll"
int Addition(int a, int b);
#import
int init() {
Print("Addition(): ", Addition(99, 1));
return(0);
}
Kapcsolódó kérdések:
Minden jog fenntartva © 2025, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!