MT4或MT5下复制文本到剪贴板的一段源码

一段MT4或MT5下复制文本到剪贴板的源码
//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright "策汇在线复制文本到剪贴板"
#property link      "http://www.fxchs.com"
#property version   "1.00"
#property strict

#import "kernel32.dll"
int GlobalAlloc(int Flags, int Size);
int GlobalLock(int hMem);
int GlobalUnlock(int hMem);
int GlobalFree(int hMem);
int lstrcpyW(int ptrhMem, string Text);
#import


#import "user32.dll"
int OpenClipboard(int hOwnerWindow);
int EmptyClipboard();
int CloseClipboard();
int SetClipboardData(int Format, int hMem);
#import

#define GMEM_MOVEABLE   2
#define CF_UNICODETEXT  13


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
{
   CopyTextToClipboard("这是个测试...!@#%!@#!#!#!#@!#!11111");
}

// 复制文本内容到剪贴板
bool CopyTextToClipboard(string Text)
{
   bool bReturnvalue = false;

   // 打开剪贴板
   if (OpenClipboard(0) != 0)
   {
      // 清空剪贴板
      if (EmptyClipboard() != 0)
      {
         // 申请剪贴内存空间
         int lnString = StringLen(Text);
         int hMem = GlobalAlloc(GMEM_MOVEABLE, (lnString * 2) + 2);
         if (hMem != 0)
         {
            // 锁定这块内存开始复制内容到内存空间
            int ptrMem = GlobalLock(hMem);
            if (ptrMem != 0)
            {
               // 复制内容到内容空间
               lstrcpyW(ptrMem, Text);
               GlobalUnlock(hMem);

               // 复制到剪贴板
               if (SetClipboardData(CF_UNICODETEXT, hMem) != 0)
               {
                  bReturnvalue = true;
               }
               else
               {
                  GlobalFree(hMem);
               }
            }
            else
            {
               GlobalFree(hMem);
            }
         }
         else
         {
            // 申请内存空间失败
         }
      }
      else
      {
         // 清空剪贴板失败
      }
      CloseClipboard();
   }
   else
   {
      // 打开剪贴板失败
   }

   return (bReturnvalue);
}
//+------------------------------------------------------------------+