Copy string to clipboard - page 2

 
#define private public
  #include <fxsaber\MultiTester\MTTester.mqh> // https://www.mql5.com/ru/code/26132
#undef private

void OnStart()
{
  MTTESTER::SetClipboard("Hello World!");
  
  string Str;
  
  if (MTTESTER::GetClipboard(Str))
    Alert(Str);
}
 
fxsaber #:

Unfortunately this class is not work

In this code I get "GlobalLock error"

string GetTextFromClipboard()
{
   string clip = "-1";
   int hMain=0;
   if(OpenClipboard(hMain))
     {
      int hglb=GetClipboardData(1); 
      if(hglb!=0)
        {
         int lptstr=GlobalLock(hglb);
         if(lptstr!=0) 
         { 
            clip=lstrcatW(lptstr,""); 
            GlobalUnlock(hglb); 
         }else Print("GlobalLock error");
        }
      CloseClipboard();
     }
   return clip;  
}
 
prg_mt4 #:

Unfortunately this class is not work

You're wrong.

 
fxsaber #:

You're wrong.

Do you know what is mistake in my code ?

I'm really confused

string GetTextFromClipboard()
{
   string clip = "-1";
   int hMain=0;
   if(OpenClipboard(hMain))
     {
      int hglb=GetClipboardData(1); 
      if(hglb!=0)
        {
         int lptstr=GlobalLock(hglb);
         if(lptstr!=0) 
         { 
            clip=lstrcatW(lptstr,""); 
            GlobalUnlock(hglb); 
         }else Print("GlobalLock error");
        }
      CloseClipboard();
     }
   return clip;  
}


 

 
prg_mt4 #:

Do you know what is mistake in my code ?

You can compare my code with yours and find the error on your own.

 
fxsaber #:
fxsaber #:

Thanks your code is perfect work.