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
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
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
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
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.
New article Getting Rid of Self-Made DLLs is published:
Author: Alex Sergeev