Wie schreibt man eine DLL? - Seite 2

 
xrust:

was die Mittel betrifft - jeder macht es auf seine Weise

Ist dieses Material frei verfügbar?
 
Das wird sie sein, wenn ich fertig bin.
 
xrust:
Das werde ich, wenn ich fertig bin.
Ja. Ich hab's.)
 

Tatsächlich wurde mir geraten, hier nach einem Anfang zu suchen http://msdn.microsoft.com/ru-ru/library/1ez7dh12.aspx

 
dmmikl86:
Ich bin ein Programmierer für 2 Jahre in MQL4, studierte das Tutorial von der Website. jetzt möchte ich lernen, wie man eine dll für mt4 zu schreiben. ich möchte lernen, wie man eine dll zu schreiben beginnen. beraten, wo Hilfe zu bekommen, was zu lesen, zuerst möchte ich einen einfachen Berater mit dll-Schlüssel Verbindung zu schreiben, die ein Fenster mit zwei Tasten BUY und SELL erstellen wird. dh Handel in einem Klick. ich bin dankbar für jede Hilfe ...

gutes Thema, gut gemacht Landsmann

Ich bin sehr neugierig darauf, meine Erfahrungen und mein Wissen mit den mt4-Programmierern zu teilen.

 
Geronimo:

gutes Thema, gut gemacht Landsmann

Und ich empfehle hartgesottenen Programmierern (wie auch Website-Administratoren), Tutorial-Zweige zu solchen Themen zu starten

Mann, wir alle brauchen deine Ratschläge, wir können einfach nicht ohne sie leben...

 
xrust:

Wir alle brauchen Ihren Rat, wir können einfach nicht ohne ihn leben...


Sie könnten einfach eine Frage mit einer guten Antwort in den FAQ-Bereich stellen....
 
dmmikl86:

können wir einfach eine Frage mit einer guten Antwort in den FAQ-Bereich aufnehmen....
OK, fügen wir hinzu
 

Ich habe versucht, meine Funktion in die .cpp einzufügen und habe es so gemacht:

//+------------------------------------------------------------------+
//|                                              Sample DLL for MQL4 |
//|                 Copyright © 2004-2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
//----
#define MT4_EXPFUNC __declspec(dllexport)
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#pragma pack(push,1)
struct RateInfo
  {
   unsigned int      ctm;
   double            open;
   double            low;
   double            high;
   double            close;
   double            vol;
  };
#pragma pack(pop)
//----
struct MqlStr
  {
   int               len;
   char             *string;
  };
static int CompareMqlStr(const void *left,const void *right);
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
  {
//----
   switch(ul_reason_for_call)
     {
      case DLL_PROCESS_ATTACH:
      case DLL_THREAD_ATTACH:
      case DLL_THREAD_DETACH:
      case DLL_PROCESS_DETACH:
         break;
     }
//----
   return(TRUE);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall GetIntValue(const int ipar)
  {
   printf("GetIntValue takes %d\n",ipar);
   return(ipar);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall myfunc(int a, int b)
  {
   int c=a+b;
   return(c);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC double __stdcall GetDoubleValue(const double dpar)
  {
   printf("GetDoubleValue takes %.8lf\n",dpar);
   return(dpar);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC char* __stdcall GetStringValue(char *spar)
  {
   printf("GetDoubleValue takes \"%s\"\n",spar);
   return(spar);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC double __stdcall GetArrayItemValue(const double *arr,const int arraysize,const int nitem)
  {
//----
   if(arr==NULL)
     {
      printf("GetArrayItemValue: NULL array\n");
      return(0.0);
     }
   if(arraysize<=0)
     {
      printf("GetArrayItemValue: wrong arraysize (%d)\n", arraysize);
      return(0.0);
     }
   if(nitem<0 || nitem>=arraysize)
     {
      printf("GetArrayItemValue: wrong item number (%d)\n", nitem);
      return(0.0);
     }
//----
   return(arr[nitem]);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC BOOL __stdcall SetArrayItemValue(double *arr,const int arraysize,const int nitem,const double value)
  {
//----
   if(arr==NULL)
     {
      printf("GetArrayItemValue: NULL array\n");
      return(FALSE);
     }
   if(arraysize<=0)
     {
      printf("GetArrayItemValue: wrong arraysize (%d)\n", arraysize);
      return(FALSE);
     }
   if(nitem<0 || nitem>=arraysize)
     {
      printf("GetArrayItemValue: wrong item number (%d)\n", nitem);
      return(FALSE);
     }
//----
   arr[nitem]=value;
   return(TRUE);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC double __stdcall GetRatesItemValue(const RateInfo* rates,const int rates_total,const int shift,const int nrate)
  {
//----
   if(rates==NULL)
     {
      printf("GetRatesItemValue: NULL array\n");
      return(0.0);
     }
//----
   if(rates_total<0)
     {
      printf("GetRatesItemValue: wrong rates_total number (%d)\n", rates_total);
      return(0.0);
     }
//----
   if(shift<0 || shift>=rates_total)
     {
      printf("GetRatesItemValue: wrong shift number (%d)\n", shift);
      return(0.0);
     }
//----
   if(nrate<0 || nrate>5)
     {
      printf("GetRatesItemValue: wrong rate index (%d)\n", nrate);
      return(0.0);
     }
//----
   int nitem=rates_total-1-shift;
   switch(nrate)
     {
      case 0: return double(rates[nitem].ctm);
      case 1: return rates[nitem].open;
      case 2: return rates[nitem].low;
      case 3: return rates[nitem].high;
      case 4: return rates[nitem].close;
      case 5: return rates[nitem].vol;
     }
//----
   return(0.0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall SortStringArray(MqlStr *arr,const int arraysize)
  {
//----
   if(arr==NULL)
     {
      printf("SortStringArray: NULL array\n");
      return(-1);
     }
   if(arraysize<=0)
     {
      printf("SortStringArray: wrong arraysize (%d)\n", arraysize);
      return(-1);
     }
//----
   qsort(arr,arraysize,sizeof(MqlStr),CompareMqlStr);
//----
   return(arraysize);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall ProcessStringArray(MqlStr *arr,const int arraysize)
  {
   int   len1,len2;
//----
   if(arr==NULL)
     {
      printf("ProcessStringArray: NULL array\n");
      return(-1);
     }
   if(arraysize<=0)
     {
      printf("ProcessStringArray: wrong arraysize (%d)\n", arraysize);
      return(-1);
     }
//----
   for(int i=0; i<arraysize-1; i++)
     {
      if(arr[i].string==NULL) len1=0;
      else len1=strlen(arr[i].string);
      if(arr[i+1].string==NULL) len2=0;
      else len2=strlen(arr[i+1].string);
      //---- uninitialized string
      if(arr[i+1].string==NULL) continue;
      //---- destination string is uninitialized and cannot be allocated within dll
      if(arr[i].string==NULL)   continue;
      //---- memory piece is less than needed and cannot be reallocated within dll
      if(arr[i].len<len1+len2)  continue;
      //---- final processing
      strcat(arr[i].string,arr[i+1].string);
     }
//----
   return(arraysize);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CompareMqlStr(const void *left,const void *right)
  {
   MqlStr *leftstr=(MqlStr *)left;
   MqlStr *rightstr=(MqlStr *)right;
//----
   if(leftstr->string==NULL) return(-1);
   if(rightstr->string==NULL) return(1);
//----
   return(strcmp(leftstr->string,rightstr->string));
  }
//+------------------------------------------------------------------+

eine Funktion zu .def hinzugefügt

LIBRARY ExpertSample

EXPORTS GetIntValue
                myfunc
        GetDoubleValue
        GetStringValue
        GetArrayItemValue
        SetArrayItemValue
        GetRatesItemValue
        SortStringArray
        ProcessStringArray

die Funktion zu .mqh hinzugefügt

#import "ExpertSample.dll"
int    GetIntValue(int);
int    myfunc(int,int);
double GetDoubleValue(double);
string GetStringValue(string);
double GetArrayItemValue(double arr[],int,int);
bool   SetArrayItemValue(double& arr[],int,int,double);
double GetRatesItemValue(double rates[][6],int,int,int);
int    SortStringArray(string& arr[],int);
int    ProcessStringArray(string& arr[],int);

und fügte sie dann dem Expert Advisor hinzu

int init()
  {
   
   double ret,some_value=10.5;
   string sret;
   int    cnt,c;
   string strarray[6]={ "first", "second", "third", "fourth", "fifth" };
//---- simple dll-functions call
   cnt=GetIntValue(some_value);
   Print("Returned value is ",cnt);
   ret=GetDoubleValue(some_value);
   Print("Returned value is ",ret);
   sret=GetStringValue("some string");
   Print("Returned value is ",sret);
//----
   cnt=SortStringArray(strarray,ArraySize(strarray));
   for(int i=0; i<cnt; i++) Print(i," - ",strarray[i]);
   cnt=ProcessStringArray(strarray,ArraySize(strarray));
   for(i=0; i<cnt; i++) Print(i," - ",strarray[i]);
//----
   int a=5;
   int b=6;
   c=myfunc(a,b);
   Comment("!!!="+c);
   return(0);
  }

Während der Fehlersuche in der Visualisierung hieß es: Das Programm "[5248] regsvr32.exe: Maschinencode" wurde mit Code 0 (0x0) beendet.

wenn ich diesen Advisor auf dem Terminal ausführe, erscheint die Fehlermeldung: 2011.07.08 12:20:14 ExportFunctions EURUSD,H1: cannot call function 'myfunc' from dll 'ExpertSample.dll'(error 127)

Bitte teilen Sie mir mit, wo die Fehler liegen und wie man sie beheben kann...

 

Hier ist der gesamte Text aus dem Debugger

"regsvr32.exe": Загружено "C:\WINDOWS\system32\regsvr32.exe"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\ntdll.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\kernel32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\msvcrt.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\advapi32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\rpcrt4.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\secur32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\user32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\gdi32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\ole32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\imm32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\MSCTF.dll"
"regsvr32.exe": Загружено "C:\Program Files\NVIDIA Corporation\nView\nView.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\comctl32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\oleaut32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\psapi.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\shell32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\shlwapi.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\winmm.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\version.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\ntmarta.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\samlib.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\wldap32.dll"
"regsvr32.exe": Загружено: "C:\Program Files\NVIDIA Corporation\nView\NVWRSRU.dll", Двоичный код не был построен с отладочной информацией.
"regsvr32.exe": Загружено "C:\WINDOWS\system32\MSCTFIME.IME"
"regsvr32.exe": Загружено "C:\Program Files\NVIDIA Corporation\nView\nvwimg.dll"
"regsvr32.exe": Выгружено: "C:\Program Files\NVIDIA Corporation\nView\nvwimg.dll"
"regsvr32.exe": Загружено "C:\WINDOWS\system32\nvwddi.dll"
"regsvr32.exe": Загружено "C:\Program Files\NVIDIA Corporation\nView\nvwimg.dll"
"regsvr32.exe": Выгружено: "C:\Program Files\NVIDIA Corporation\nView\nvwimg.dll"
Программа "[4944] regsvr32.exe: Машинный код" завершилась с кодом 1 (0x1).