[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 250

 
TarasBY:
First, you calculate the current profit on all open orders, then you compare it with the declared level: if it is higher, you delete all orders. This procedure (and not only) is done by this EA (the code is there too).

Thanks for the tip
 

I don't understand.

gyfto:
//C++
MT4_EXPFUNC int __stdcall GetStrAddress(const char *str) {    
    MqlStr* s = (MqlStr*)str;
    return (int)s->string; 
}

Zhunko:
It's still like this:

MT4_EXPFUNC int stdcall GetStrAddress(LPCSTR szStr)
 {    
  return(int(szStr));
 }

Ran it three times with this code:

#property indicator_chart_window
#import "stdlib.ex4"
string IntegerToHexString(int integer_number);
#import "StrAddress.dll"
int OldGetStrAddress(string str);
int GetStrAddress(string szStr);
#import

int addrOld;
int addrNew;

int init()
  {
   string s=""; strAddress (s);
   s=s+"something"; strAddress (s);
   s="MyStr"; strAddress (s);
   s="mystr"; strAddress (s);
   return(0);
  }

int start()
  {
   return(0);
  }
void strAddress (string myStr)
  {
   addrOld=OldGetStrAddress(myStr);
   addrNew=GetStrAddress(myStr);
   Print(" строка ", CharToStr(34), myStr, CharToStr(34), ", старый вариант: ", IntegerToHexString(addrOld), ", новый вариант: ", IntegerToHexString(addrNew));
  }

It's reflected in the log:

строка "", старый вариант: 656D6F73, новый вариант: 01CD8A90
строка "something", старый вариант: 6E696874, новый вариант: 01CD9010
строка "MyStr", старый вариант: 00360072, новый вариант: 01CD8AA0
строка "mystr", старый вариант: 00360072, новый вариант: 01CD8AA8

строка "", старый вариант: 656D6F73, новый вариант: 01C97858
строка "something", старый вариант: 6E696874, новый вариант: 01CDCC30
строка "MyStr", старый вариант: 00360072, новый вариант: 01C978868
строка "mystr", старый вариант: 00360072, новый вариант: 01C997870

строка "", старый вариант: 656D6F73, новый вариант: 01D93108
строка "something", старый вариант: 6E696874, новый вариант: 01CC5A58
строка "MyStr", старый вариант: 00360072, новый вариант: 01D93118
строка "mystr", старый вариант: 00360072, новый вариант: 01D93120

In the first case we have a pointer to the first element of the MqlStr.string structure field, in the second case we have a pointer to the first element of the string (LPCSTR still the sameconst char*). We see different addresses. W-why? It turns out that the string as an array char and the string as an internal structure of its representation in MQL4 have different addresses? Or it means that "string structure" described in ExpertSample as internal format is artificial, and its internal format in MQL4 is lpsz? Or maybe I've got the first code wrong?

 
Hello all. Can you please advise me, after compilations on the icon of the EA appears a lock and I can only see it in the download window through the program and in the folder it is invisible, how to fix it? Can you fix it?
 
In some examples, I see return(-1), return(0) or just return. I use return(0) to interrupt the program from this location. Can you tell me what return(-1) and return do?
 
gyfto:
Or does it mean that the "string structure", described in ExpertSample as internal format, is artificial, and in fact its internal format in MQL4 is lpsz?

This means that in DLL the string is transferred exactly as char* and not as MqlStr. But it does not mean that in ex4 program the string is not stored as MqlString. In general, the transfer of parameters from ex4 to dll is (according to the developers) a rather complex process, accompanied by all kinds of checks and transformations of parameters.
 
laveosa:
Hello all. Can you please advise me, after compilations on the icon of the EA appears a lock and I can only see it in the download window through the program and in the folder it is invisible, how to fix it? Thank you.
Win 7 and the terminal is on the system drive? You want to get rid of current and future problems - move the terminal to another drive and "everything will work out".
 
paladin80:
In some examples, I see return(-1), return(0) or just return. I use return(0) to interrupt the program from this location. Can you tell me what return(-1) and return do?
It is the return value returned by the function. Go back to the Math.
 
paladin80:
In some examples, I see return(-1), return(0) or just return. I use return(0) to abort the program from this place. Please tell me, what do return(-1) and return do?

return(-1) returns minus one as the result of the function, which (-1) can only mean something if the developer of that program put it there himself. Otherwise, it means nothing.

return simply terminates the function (used when the return type is void).

 
TarasBY:
This is the value returned by the function. Go back to the math.

In general, return(0) stops the int start() function and waits for the next tick. If there is no digit or it is -1, what happens in int start()?

 
TarasBY:
Win 7 and the terminal is on the system drive? Want to get rid of current and future problems - move the terminal to another drive and "everything will work out".

Thanks a lot :) I'll give it a try.
Reason: