Discussion of article "Getting Rid of Self-Made DLLs"

 

New article Getting Rid of Self-Made DLLs is published:

If MQL5 language functional is not enough for fulfilling tasks, an MQL5 programmer has to use additional tools. He\she has to pass to another programming language and create an intermediate DLL. MQL5 has the possibility to present various data types and transfer them to API but, unfortunately, MQL5 cannot solve the issue concerning data extraction from the accepted pointer. In this article we will dot all the "i"s and show simple mechanisms of exchanging and working with complex data types.


Author: Alex Sergeev

[Deleted]  
Thanks for the article, question: when using memcpy function, in the example we wrote the address in int, if the system is x64, should we use long variable? How can we programmatically find out what system (x64, x86)? Thanks.
 

on the question of long - you can, but it is not necessary at all, if you use int as a 4 byte receiver of something like that from an array of chars. (i.e. you pass exactly by the & pointer).

how to find out - here you can http://forum.ixbt.com/topic.cgi?id=26:37968

 
sergeev:

on the question of long - you can, but it is not necessary at all, if you use int as a 4 byte receiver of something like that from an array of chars. (i.e. you pass exactly by the & pointer).

How to find out - here it can be http://forum.ixbt.com/topic.cgi?id=26:37968

Can you clarify something about the exchange time in this structure (for example, for 10 numbers of Int format)?
 
shelandr:
Can you clarify something about the Exchange Time in this structure (for example, for 10 numbers of Int format)?

clarify the question.

are you asking about memcpy speed? I think this is a creative question related more to the work of a wind library than to mql.

 
Most useful and informative article regarding working with external DLL APIs. Thank you so much.
 

Good afternoon. Despite the fact that the article was written relatively long ago, the issue of data exchange with library dlls is still relevant. I myself recently faced the need to implement a certain functionality and I had a choice: to write my own dll or still try to use library dlls. I made a choice in favour of the latter and naturally faced the difficulty of transferring structures and getting data back. After reading this article I did not quite grasp some of the points, which in my opinion are very complicated. In this article, when transferring a structure to an external environment, it is suggested to use an array as an allocated memory area in which the library function will put the result and which we need to convert for further work. I have very little experience in this area and perhaps my reasoning will seem amateurish, but I will still express my opinion in the hope that smart people will correct me. Let's consider a simple example mentioned in an old article https://www.mql5.com/en/articles/1543.

That article deals with the issue of searching files by means of library dlls. It also suggests passing a pointer to an array of the required size and then extracting the required data from this array.

What is a structure? It is the same memory section. Now let's try to change the approach to passing structures and retrieving data:

// Declare data type defines

#define  DWORD int
#define  TCHAR short // Set this type, as we will work with unicode
#define  MAX_PATH (260)

// Declare the FILETIME structure
struct FILETIME {
  DWORD dwLowDateTime;
  DWORD dwHighDateTime; 
};

// Declare the data structure of search results
struct _WIN32_FIND_DATA {
  DWORD dwFileAttributes;
  FILETIME ftCreationTime;
  FILETIME ftLastAccessTime;
  FILETIME ftLastWriteTime;
  DWORD nFileSizeHigh;
  DWORD nFileSizeLow;
  DWORD dwReserved0;
  DWORD dwReserved1;
  TCHAR cFileName[MAX_PATH];
  TCHAR cAlternateFileName[14]; 
};

// By declaring data types we copy WinAPI structures without any changes at all
// Import library function
#import "kernel32.dll"
   int  FindFirstFileW(string path, _WIN32_FIND_DATA& answer);
#import 
//+------------------------------------------------------------------+
//| Expert initialisation function|
//+------------------------------------------------------------------+
int OnInit()
  {
// Create a variable with the type of the previously created structure 
   _WIN32_FIND_DATA data;
// Call the library function, passing a pointer to our structure, and in fact to the allocated memory 
int handle = FindFirstFileW(TerminalInfoString(TERMINAL_DATA_PATH) + "\\MQL5\\Experts\\*.mq5", data);
   if(handle!=-1)
      {
        // View the search result by accessing the fields of our structure without additional conversion 
Print("Found file name: ", ShortArrayToString(data.cFileName));   
         Print("Temporary found file name: ", ShortArrayToString(data.cAlternateFileName));
         Print("Found file size: ", data.nFileSizeLow); 
      }
//---
   return(INIT_SUCCEEDED);
  }
//+-
Групповые файловые операции
Групповые файловые операции
  • 2008.07.15
  • MetaQuotes Software Corp.
  • www.mql5.com
Иногда требуется проделать одинаковые операции для некоторой группы файлов. Если у вас есть список файлов, входящих в эту группу, то это не проблема. Но если этот список нужно получить самостоятельно, то возникает вопрос: "Каким образом?" В статье предлагается сделать это с помощью функций FindFirstFile() и FindNextFile(), входящих в библиотеку kernel32.dll.
 
Алексей Барбашин: There is also a suggestion to pass a pointer to an array of the required size and then extract the required data from this array. They also suggest passing a pointer to an array of the required size and then extracting the required data from this array.

What is a structure in essence? It is the same memory section. Now let's try to change the approach to passing structures and retrieving data:

I pasted your code correctly through the editor

 
Rashid Umarov:

Pasted your code correctly through the editor


Thanks a lot! I haven't figured out how to format the code correctly here yet. (((

 
Алексей Барбашин:

Thank you very much! I haven't figured out how to properly code here yet. (((


How to insert the code.

 
Vladimir Karputov:

How to insert the code.


Thank you! I'll look into it! )))