dll pointer handling deprecated?

Tobias Johannes Zimmer  

Hello,

I was reading this very old article, https://www.mql5.com/en/articles/19 where the author has a dll get the pointer adress (which mql5 doesn't allow you to). The use was to not be copying values back and forth, but accessing the indicators buffers directly.

Really interesting what the author did there... Now I was trying to make it work, there was a dll that I put into the Libraries folder, and an mqh which I put into Includes folder.

Then after compiling apparently without any problem, upon debugging with historical data there is an error message:

dllptrdeprecated

Now, my interest has been sparked, I am thinking about how to get into the dll nitty-gritty. Maybe the authors dll was just 32bit because the article is so old and maybe I need to make a 64bit version. Now it should be possible to create a new dll from Visual Studio, at least its C++ source file doesn't contain much code:

extern "C" __declspec(dllexport) int __stdcall GetPtr(double *a) // This here might be the problem, see below.
{
        return((int)a); 
}

extern "C" __declspec(dllexport) double __stdcall GetValue(int pointer,int i)
{
        return(((double*) pointer)[i]);
}

extern "C" __declspec(dllexport) void __stdcall SetValue(int pointer,int i,double value)
{
        ((double*) pointer)[i]=value;
}

//That's all folks, entire content of the maindll.cpp file which I couldn't upload


After searching for dll in documentary, here I found this on imported functions:

"The following can't be used for parameters in imported functions:

Classes, string arrays or complex objects that contain strings and/or dynamic arrays of any types cannot be passed as a parameter to functions imported from DLL."

I am somehow not yet convinced that this means what I am afraid it does. The author doesn't respond to my comment under his article.
So passing a pointer to a dll is now deprecated so the article above is completely outdated and there is no use in trying to make it work?


Sry I can't upload a cpp file.

Data Exchange between Indicators: It's Easy
Data Exchange between Indicators: It's Easy
  • www.mql5.com
We want to create such an environment, which would provide access to data of indicators attached to a chart, and would have the following properties: absence of data copying; minimal modification of the code of available methods, if we need to use them; MQL code is preferable (of course, we have to use DLL, but we will use just a dozen of strings of C++ code). The article describes an easy method to develop a program environment for the MetaTrader terminal, that would provide means for accessing indicator buffers from other MQL programs.
Files:
ATR_alex.mq5  5 kb
exchng.mqh  1 kb
exchng.mq5  13 kb
Soewono Effendi  
>>> Sry I can't upload a cpp file.

Give it a fake extension name, e
g. .mqh , i.e. test-cpp.mqh

Fernando Carreiro  
Tobias Johannes Zimmer: Sry I can't upload a cpp file.

Files of any other type not directly supported by the forum, should be provide in a ZIP archive attachment. That way, all file extensions or directory structures are preserved.

William Roeder  
7z is free, open source, better compression, and supports zip and rar.
Tobias Johannes Zimmer  

Okay thanks everybody for the info about the upload. As mentioned, the dll's source code really only consists of the six lines above. Nonetheless, you will find the zipped code attached.

Also if you are interested, all the resources can be downloaded from the "article 19" which is linked in the original topic.


My question is also when I work with Classes I can use a pointer to get access to contained abstract types and their methods like so:

//+------------------------------------------------------------------+
//| Base class to demonstrate access to private members via methods  |
//+------------------------------------------------------------------+
class CTestBase 
  {
private:

   int               m_SecondsSince1970;
   double            m_Price;

public:
                     CTestBase(void): m_SecondsSince1970(100000), m_Price(1.3425) {};
                    ~CTestBase(void) {};
   int               GetSecondsSince1970(void) {return(m_SecondsSince1970);}
   double            GetPrice(void) {return(m_Price);}
  };


//+------------------------------------------------------------------+
//| Test class to demonstrate access to the private members of the   |
//| parent class through referenced Pointers of parent instances     |
//+------------------------------------------------------------------+
class CTest
  {
private:
   CTestBase         m_Base_array[4];   // CTestBase is here the abstract data type of the array members
                                        
public:
                     CTest(void) {};
                    ~CTest(void) {};
   CTestBase         *GetBaseInstance(int a_index) {return(&m_Base_array[a_index]);}
  };                                    // and here the "pointer" is returned by reference to the instance
                                        // of parent class in the m_Base_array

CTest test;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   for(int i = 0; i < 4; i++)
     {
      printf("Price: %g, SecondsSince1970: %d", test.GetBaseInstance(i).GetPrice(), test.GetBaseInstance(i).GetSecondsSince1970());
     }
//---
   return(INIT_SUCCEEDED);
  }

I know for a fact that in an earlier version of MQL5 the debugger showed the pointer adress in variable observations... like 00x0123... something something. But one can't store the pointer adress in an int format by means of mql alone. Which is what the Article is about: the author stores the pointer adresses inside global variables with unique names.

Files:
cppq18.zip  1 kb