different results using a dll function

 

Hi,


I've got a real strange problem using a dll with MetaTrader:


I've written a 2 Indicators and 1 dll. Both indicators call the dll to caclulate its values. Indicator 1 calls function1 from the dll to get its values and Indicator 2 calls function2 from the dll to get its values. Indicator 2 can only return results if Indicator 1 have returned a result. Therefore, the dll function function2 calls the dll function function1. The strange thing is, that both calls of function1 ( a) directly from indicator 1 and b) through indicator 2(that means function1 is called from function2)) return different results. In detail it means, that the call of function1 through indicator 2 returns more results then the call through indicator 1.

Does anyone of you have an idea, why such things happen????

(maybe metatrader is building the stack in a wrong way or something like that)


Thank you very much in advance

 

You are complicating it quite a lot.

I understand that:


MyDll.dll:

Function1() {}

Function2() {}


Indicator1.mq5:

#import "MyDll.dll", (Function1, Function2);

Fucntion1(SourceData);


Indicator2.mq5:

#import "MyDll.dll", (Function1, Function2);

DestData=Function2();


CPU understands:

Function2(Function1);


====================

Answer. I'm sorry, but you have dont describe the problem very well.

I understand, You have been trying to pass the table between indicators.

Yes, I have the same problem very often, I'm using SendMessage() like functions

to pass small pice of data, but they can be serial sent.

Passing Tables by files is dengerous and demand of virtual drive mapped in Files folder.


Everyone have the same problem - its hard to pass a large portions of data between indicators.

You can use the DLL, but its probably the solve of your problem.  Every Indicator its separate thread

inside the task called MetaTrader5.  You are loading the same DLL from different threads, and good,

but there are separate memory areas with code of DLL and them data, and to pass the table

between separate DLLs You Have To call an operating system function from DLL (maybe kernel32.dll,

that you of course must append to the indicator, to have an entry points to the operating systems)

and from MyDll.dll you must call kernel32.dll function, that guarantees common memory variable,

that synchronizes the tables between MyDll.dll.


This is the solution - tables in your two MyDll.dll are not sychronized, and to do this you must

call an kernel32.dll that recives you an pointer to the Table2 inside Indicator1, and then you

can copy and sychronize data.  Its hard to write - "To share the large data by Indicators"'.


Every one Indicator is an thread and have there own stack.  This is not nestes stack, like

open next stack frame (MOV EBP,ESP  SUB ESP,4096  - opened 4kB stack frame).  They have

the separate (not nested stacks) swiched by operating system when the thread (Indicator)

must be lived.  And every Indicator have they own data on they private stack.  And there

is the problem with sharing data between indicators.  Everyone have this problem.


#  Calling DLL is good, but the DLL must be perfectly written to call the operating system

   function, that copies data from stack of Indicator1 to stack of Indicator2 - its hard to write.

#  Files comunication its dangerous if you very often call the HDD.  I recomand virtual drive.

# Comunication like SendMsg() and OnMsg() - its fast, but not above 1MB.

# And there is jet the method of comunication by GlobalVariables();


Good luck.