Libraries: File Mapping without DLL - page 5

 
baramantan:

I'm not a mega programmer. But I don't understand where universality is? uchar cannot be universal because it limits the user, namely: uchar is only for positive values. The minimum value is zero, the maximum value is 255.

Any data beyond the value of uchar becomes equal to the maximum or minimum value of uchar.

Based on what I said, I asked from the beginning "how to pass int or double". I'm not following you, chief.

OK. Let's take a little tour.

1. Let's take the example of char and uchar. Both variables are 1 byte in size.

This means that by assigning to each other we don' t lose bytes and therefore we don' t lose the value of the original data.

look at these expressions

uchar u=200; char c=u; u=c; Print(u);
c=-100; u=c; c=u; Print(c);

The same is true for long/ulong, int/uint.

That is, variables of integer type of the same size in bytes can be passed to each other without losing bytes of information.

By the way, this means that although the Expert Advisor accepts MAGIC numbers in ulong type, you can always set and read them in long, i.e. in the signed format, in your programmes


2. now look at <some_type> and uchar.
For example int. As you know from sizeof(int) it has a size of 4 bytes. This means that these 4 bytes in memory can be easily represented as uchar[4] array
if there is a double (it is 8 bytes), it can be represented as uchar[8] array
This also applies to bytes of strings - in MQL it is ushort array.
well and accordingly if you have a structure of any type, you can easily provide any data as uchar array.

It is these basic concepts about bytes that are used in MQL5 version - virtual files in memory CFastFile. It stores any data in the uchar array memory.

That is, if you do not need to exchange data with external programmes. Or you receive data from another program in the form of a data stream - for example, reading Internet pages, and this data does not need to save all on disc, then it is better to use CFastFile instead of the Windows mapping.

and lastly, to fully consolidate https://www.mql5.com/en/articles/364.

 
BoraBo:

MT5 642 Win7 64 does not work, as far as I understand it, after

hmem=CreateFileMapping(INVALID_HANDLE_VALUE,NULL,PAGE_READWRITE,0,size+HEAD_MEM,path); // create memory object

I get error 1400,

but Vista 32 works.


it is because of different pointer sizes in 32 and 64 systems

this library file is made for a 32-bit terminal.

but if you use a 64-bit terminal, you should put 8-byte long type in all places where a pointer is implied (for example PBYTE, LPVOID, etc., and in all memcpy types).

 

but how do I connect

#include <MemMapLib.mqh>
#include <Trade\Trade.mqh> 

It's coming out.

'GetLastError' - ambiguous call to overloaded function with the same parameters SymbolInfo.mqh  718     10
'GetLastError' - ambiguous call to overloaded function with the same parameters	SymbolInfo.mqh	725	57

and these two inludes work without each other.

 
olyakish:

but how do I connect

It gives out

and these two inclusions work without each other.

try to use context resolution ::
 
sergeev:
try to use context resolution ::

Thanks

I just had to modify the standard library.

//+------------------------------------------------------------------+
bool CSymbolInfo::CheckMarketWatch(void)
  {
//--- check if symbol is selected in the MarketWatch
   if(!Select())
     {
      if(::GetLastError()==ERR_MARKET_UNKNOWN_SYMBOL)
        {
         printf(__FUNCTION__+": Unknown symbol '%s'",m_name);
         return(false);
        }
      if(!Select(true))
        {
         printf(__FUNCTION__+": Error adding symbol %d",::GetLastError());
         return(false);
        }
     }
//--- succeed
   return(true);
  }
//+------------------------------------------------------------------+
I don't think that's a good thing....
 
olyakish:

Thank you.

I just had to modify the standard library.

I don't think that's a good thing.

You don't understand.

I told you about kernel32::GetLastError. Look how it is implemented in my code.

If you are not satisfied with this option, then declare import from kernel32 GetLastError for example with int parameter. there will be no difference when calling it, but you will avoid conflict.

 
sergeev:

you don't understand.

I told you about kernel32::GetLastError. Look how it is implemented in my code.

If this option does not suit you, then declare import from kernel32 GetLastError for example with int parameter. there will be no difference when calling it, but you will avoid conflict.

Perhaps I'm not stating it correctly.

but we have to

because here's an example of your code with the standard library attached.

//+------------------------------------------------------------------+
//|MemMap |
//| Copyright © 2006-2013, FINEXWARE Technologies GmbH |
//| www.FINEXWARE.com |
//| programming & development - Alexey Sergeev, Boris Gershanov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006-2013, FINEXWARE Technologies GmbH"
#property link      "www.FINEXWARE.com"
#property version   "1.00"
#include <MemMapLib.mqh>
#include <Trade\Trade.mqh> 


//------------------------------------------------------------------ OnStart
void OnStart()
{
        CMemMapFile hmem;
        long err=hmem.Open("Local\\test",111,modeCreate);
        
        uchar data[];
        StringToCharArray("Hello from MQL5!",data);
        err=hmem.Write(data,ArraySize(data));
        
        ArrayInitialize(data,0);
        hmem.Seek(0,SEEK_SET);
        err=hmem.Read(data,ArraySize(data));
        Print(CharArrayToString(data));
        
        hmem.Close();
}

When compiling it gives the same errors.

 

olyakish, read again carefully what I wrote to you.

If you're not satisfied with the context, I'm telling you exactly what I mean.

  • "or what to change for your library".
 
sergeev:

you don't understand.

I told you about kernel32::GetLastError. Look how it is implemented in my code.

If this option does not suit you, then declare import from kernel32 GetLastError for example with int parameter. there will be no difference when calling it, but you will avoid conflict.

When calling kernel32::GetLastError with its context in the code , the compiler will call GetLastError without context.

Programmers just need to make it a rule to call MQL-analogues of standard WinAPI functions with context. Then there will be no problems with subsequent modification.

And so you fix the standard bible and it will be updated, so you have to edit it again.

 
Urain:

And so you fix the standard biblical and it will be updated, again you have to edit it.

The standard one is the standard one, so there is nothing to do there, no way. There is an error -- report to the developers. No other way.