importing DLL functions

 
I am having trouble importing DLL functions that expect a pointer to a string.

Something like this:

#import "user32.dll"
    int GetWindowTextA(int hwnd,string &lpstring,int nMaxCount);
#import

So, after finding out the hwnd, I call the function and pass the lpstring, after I previously initialize it with 50 spaces... and I get it the same out of the function (of course with a MaxLength of 30 (should have used GetWindowTextLength, but I knew exactly to which window the handle belongs :))  ) )

The & shouldn't instruct MetaTrader to pass the internal pointer, which is then linked tot the represented variable ?
 
Try this way

#import "user32.dll"
    int GetWindowTextA(int hwnd,string & lpstring,int nMaxCount);
#import
 
....
string Text[1]={""};
int  valueInt=GetWindowTextA(handlewnd,Text[0],MaxCount);
Print(Text[0]);

See also 'Crash в "About"' and 'Скрипт "Каталог программы"'
 
Thanks Rosh, that worked! Only difference is that , for correct retrieval, MaxCount must be GetWindowTextLengthA(handle)+1 instead of GetWindowTextLength(handle). Don't know why it requests an extra char.
 
You're welcome.
 
STRANGE!

We both made a mistake. Even me, when I wrote the example.
By accident, I used the & operator when writing my post, as It is technically true, but my example works WITHOUT it. If i put that operator there, the compiler rejects the effective parameter pass when calling the function, as being in "incompatible types" situation. Looks fishy for the compiler to do that...
 
There is side effect with passing strings as reference. See https://www.mql5.com/en/forum/46512 my answer at 28.03.07 10:00
 

Hi, I tested import 2 *.dll to my code, but compiler return error message: double quotes needed

I am not author *.dll files. What do you mean error message? If possible the same name any function inside dll?

 
  1. Why are you replying to a five year old post?
  2. No mind-readers here. Post your code.

  3. Play video
    Please edit your post.
    For large amounts of code, attach it.
Reason: