Discussion of article "Guide to writing a DLL for MQL5 in Delphi" - page 2

 
marketeer:
You should add at least a paragraph about debugging. The article mentions one situation when AV may occur, but even leaving aside the sea of other potential sources of exeptsions, trying to manually (by eye or mentally) search for the error location can take a very long time and without success.

Thanks for your comment. I think this section can be expanded to include the most popular errors. However, to avoid searching for errors "long and unsuccessfully", do everything as it is written in the article. The examples in it are workable. Besides, use the debugger in MetaEditor, it is quite decent, with step-by-step debugging and breakpoints!

In this article, I don't want to teach anyone how to program. If someone makes elementary errors and then shouts loudly, , maybe he should not create his own DLLs yet and start learning the mat part.

 

Hello HideYourRichess.

You are so fast! You have written so much! You should write your own articles on Delphi.

I will try to answer briefly and in order:

1. Юниты SysUtils и Classes нужно было оставить в проекте.

SysUtils are in the project! Classes have nothing to do! Exception handler besides SysUtils is implemented in System, which is connected by default, so I see no reason to worry.

2. You should not use all sorts of procedures within DllEntryPoint (aka DllMain).

The DllEntryPoint example is on the internet on every corner. This is a standard way of creating DLL events, to which, for example, you can bind the allocation and release of memory from the heap. If you have real errors with this method of working with memory, I am ready to consider it.

I don't argue about everything else that cannot be done in DllEntryPoint, because I don't use it often.

3. You have written a lot about the memory manager. I will only highlight your conclusion:

So you can make the DLL and the application have a single memory manager, and it will be the MT4 memory manager.

The problem is that none of us know how the memory manager in MT5(MT4) works. And even if we knew the names of functions that implement this manager, how are you going to use it, because the API for MT5is closed! So the idea of a single MT5 manager and DLL is utopia.

In order not to confuse the readers, I suggest instead to use the classical memory handling technique implemented in APIfunctions . It is described in the article in the section of working with strings.

I count on the fact that instead of quoting Delphi books and articles here, the author of the article will be given claims only in connection with what really does not work from what is described in the article. Preferably with examples.


 
avoitenko :

Thank you for your comment. I think this section can be expanded to include the most popular errors. However, to avoid searching for errors "long and unsuccessfully", do everything as it is written in the article. The examples in it are workable. Besides, use the debugger in MetaEditor, it is quite decent, with step-by-step debugging and breakpoints!

In this article, I don't want to teach anyone how to program. If someone makes elementary errors and then shouts loudly, , maybe he should not create his own DLLs yet and start learning the mat part.

Alas, you are very much mistaken. Not only those who are learning to program make mistakes - both elementary and not so elementary - but also skilled programmers.

This has nothing to do with the mathematics, but with debugging tools. Let's remember the well-known "80 by 20" statistic: 80% of time is spent on debugging and only 20% on writing code. As far as I understand, the goal of the article is to teach you how to write a workable DLL, i.e. not only the specific example given but also a hypothetical other code. Of course, it is impossible to consider all potential errors, but we need information on how to catch them in principle. Otherwise, readers won't be able to do anything but reproduce the example.

MetaEditor has nothing to do with it either, because we are talking about debugging DLL, i.e. its internals.

You are the author - you know better. I just expressed my opinion about some incompleteness in the presentation.

 
"You're so quick! You've written so much! You should write your own articles on Delphi."

These are excerpts from an old article on dlls for mt4, unfinished. I just copied the extracts here. It's not hard and it's not long.

"SysUtils are in the project! Classes have nothing to do with it! The exception handler besides SysUtils is implemented in System which is connected by default, so I don't see any reason to worry. "

It's up to the owner what units to include. But I think it is necessary to specify why. In this case, SysUtils and Classes are recommended by borland. And there are reasons for that.

"The example with DllEntryPoint is given on the Internet on every corner. This is a standard way of creating DLL events, to which, for example,"

Borland didn't hide DllMain from naughty hands by accident. The standard way of creating a DLL in Delphi is with a hidden DllMain. Think about why this is so. And read what Microsoft itself recommends.

"You can bind memory allocation and release from the heap. If you have real errors with this method of working with memory, I'm ready to consider it."

That's up to you. But my recommendation is that nothing should be done in DllMain at all.

"The problem is that none of us know how the memory manager in MT5(MT4) works. And even if we knew the names of functions that implement this manager, how are you going to use it, because the API for MT5is closed! So the idea of a single MT5 manager and DLL is utopia."

;-) for someone it is "closed" and "utopia" - and for someone else "everything works". we are talking about 4. I haven't looked at 5.

 

It should be mentioned that there is an alternative to using Delphi.

If you are not already a Delphi user you should consider using Lazarus/FPC, it is open source, has almost the same features as Delphi (and even some more), is largely compatible with Delphi source code and I would even bet that all of the above examples compile in Lazarus without any modifications.

If you prefer open source over proprietary software (which is something you should do anyways) then Lazarus is what you are looking for and not a commercial trial version of Delphi.

 

There is such a procedure in the article:

//----------------------------------------------------------+
procedure DLLEntryPoint(dwReason: DWord); // event handler
//----------------------------------------------------------+
begin
    case dwReason of

      DLL_PROCESS_ATTACH: // DLL is attached to the process;
          // memory allocation
          Buffer:=AllocMem(BUFFER_SIZE);

      DLL_PROCESS_DETACH: // DLL is disconnected from the process;
          // freeing memory
          FreeMem(Buffer);

    end;
end;

The compiler asks me what the undeclared variable BUFFER_SIZE is.

Could you please tell me what it really should be and where it should be declared and what buffer it is about?

 
lucka88:

The compiler asks me what the undeclared variable BUFFER_SIZE is.

Could you please tell me what should be there and where it should be declared and what buffer we are talking about?

In the project file dll_mql5.dpr there is the following declaration

const BUFFER_SIZE = 255;

By a line of code

Buffer:=AllocMem(BUFFER_SIZE);

memory for storing the string is allocated in the heap.

And the Buffer pointer itself is used in the GetStringBuffer function, which demonstrates working with strings.

 

DLL help
 

Can anyone help guide me .. Can we use MT4 DLL file on MT5 and if yes... where do you instill it in MT5 and any thing else i need to know.

 

Also which folder do we store the DLL file in ??? 

I do not have the code for the DLL anymore so i really cant rewrite it anymore.

 

 

any suggestion and help will be appreciated.  

 

When connecting the Expert Advisor in MT5 I get the error "dll is not 64-bit version".

Is there any way to use 32bit dll?

If not, can anyone tell me how to compile a 64bit dll in Delphi XE?

 
meneo:

how to compile 64it dll in Delphi XE?

Support for 64 bit appeared in Delphi XE2 and Lazarus.