Discussion of article "Getting Rid of Self-Made DLLs" - page 4

 
Maxim Kuznetsov #:

the last parameter (which is cnt) is also 64 bits. It is size_t

https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/memcpy-wmemcpy

Thanks.

 
Maxim Kuznetsov #:

of course it does...prototypes are from 4 (32 bit address a la unsigned int), and you compile/run in 5 (it has 64).

Retarded, I wrote via longs earlier myself.

#define  MEMCPY_MACROS(A)                                                     \
long memcpy( const long Destination, const A &Source[], const uint Length ); \
long memcpy( A &Destination[], const long Source, const uint Length );
 
Edgar Akhmadeev #:

I missed the point with the 64bit address. But I'm still crashing with the corrected address. Is it sure it should work? Can I see a full example of the corrected fxsaber code?

So far I am still of my own opinion - the address from WinAPI is incompatible with MQL.

I found a mistake, why the corrected version did not work for me. I made a typo, missed & in one place.

My opinion has changed, thank you all.

 

By the way, MS considers the memcpy function unsafe and obsolete and suggests memcpy_s instead. Besides, the first parameter is not const. So the result is:

#define  DEF_MEMCPY_S(T)                                                   \
        ulong memcpy_s(T &dst,   ulong size, const ulong src, ulong cnt); \
        ulong memcpy_s(T &dst[], ulong size, const ulong src, ulong cnt); \
        ulong memcpy_s(T &dst,   ulong size, const T &src[],  ulong cnt); \
        ulong memcpy_s(T &dst[], ulong size, const T &src[],  ulong cnt);
        
#import "msvcrt.dll"
        DEF_MEMCPY_S(char)
        DEF_MEMCPY_S(uchar)
        DEF_MEMCPY_S(int)
        DEF_MEMCPY_S(uint)
        DEF_MEMCPY_S(long)
        DEF_MEMCPY_S(ulong)
#import



void OnStart() {
        int Array[];
        ArrayResize(Array, 1);
        Array[0] = 123;
        int Value1 = 0;
        int Value2 = 0;
        
        ulong Address = memcpy(Array, 0, 0);
        memcpy_s(Value1, sizeof(int), Address, sizeof(int));
        
        memcpy_s(Value2, sizeof(int), Array,   sizeof(int));
        
        Print(Value1, " ", Value2);
}
 

Interesting examples. A question for connoisseurs. Is it possible to get the address of a vector, matrix, object of any class?

 
Denis Kirichenko #:

Interesting examples. Question for connoisseurs. Is it possible to get the address of a vector, matrix, object of any class?

no