Advertisement
expired6978

Untitled

Oct 19th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1.  
  2. class SKSEScaleform_GetClipboardData : public GFxFunctionHandler
  3. {
  4. public:
  5.     virtual void    Invoke(Args * args)
  6.     {
  7.         if (! g_loadGameLock.TryEnter())
  8.             return;
  9.  
  10.         if(OpenClipboard(NULL))
  11.         {
  12.             BOOL unicode = IsClipboardFormatAvailable(CF_UNICODETEXT);
  13.             BOOL utf8 = IsClipboardFormatAvailable(CF_TEXT);
  14.             if(unicode || utf8)
  15.             {
  16.                 HANDLE  handle = GetClipboardData(unicode ? CF_UNICODETEXT : CF_TEXT);
  17.                 if(handle)
  18.                 {
  19.                     LPTSTR  textData = (LPTSTR)GlobalLock(handle);
  20.                     if(textData)
  21.                     {
  22.                         if(unicode)
  23.                             args->movie->CreateWideString(args->result, (const wchar_t*)textData);
  24.                         else
  25.                             args->movie->CreateString(args->result, (const char*)textData);
  26.  
  27.                         GlobalUnlock(handle);
  28.                     }
  29.                 }
  30.             }
  31.  
  32.             CloseClipboard();
  33.         }
  34.        
  35.         g_loadGameLock.Leave();
  36.     }
  37. };
  38.  
  39. class SKSEScaleform_SetClipboardData : public GFxFunctionHandler
  40. {
  41. public:
  42.     virtual void    Invoke(Args * args)
  43.     {
  44.         if(!g_loadGameLock.TryEnter())
  45.             return;
  46.  
  47.         if(OpenClipboard(NULL))
  48.         {
  49.             const wchar_t   * textUnicode = args->args[0].GetWideString();
  50.             const char      * textUtf8 = args->args[0].GetString();
  51.             void            * textIn = NULL;
  52.  
  53.             UInt32          size = 0;
  54.             if(textUnicode) {
  55.                 size = (wcslen(textUnicode) + 1) * sizeof(wchar_t);
  56.                 textIn = (void*)textUnicode;
  57.             }
  58.             else if(textUtf8) {
  59.                 size = strlen(textUtf8) + 1;
  60.                 textIn = (void*)textUtf8;
  61.             }
  62.            
  63.             if(textIn && size > 0)
  64.             {
  65.                 HANDLE  handle = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, size);
  66.                 if(handle)
  67.                 {
  68.                     LPTSTR  textData = (LPTSTR)GlobalLock(handle);
  69.                     if(textData)
  70.                     {
  71.                         memcpy(textData, textIn, size);
  72.                         GlobalUnlock(handle);
  73.  
  74.                         EmptyClipboard();
  75.                         if(SetClipboardData(textUtf8 ? CF_TEXT : CF_UNICODETEXT, handle))
  76.                         {
  77.                             handle = NULL;  // ownership passed to the OS
  78.                         }
  79.                     }
  80.  
  81.                     // clean up the allocation if something failed
  82.                     if(handle)
  83.                     {
  84.                         GlobalFree(handle);
  85.                     }
  86.                 }
  87.             }
  88.  
  89.             CloseClipboard();
  90.         }
  91.  
  92.         g_loadGameLock.Leave();
  93.     }
  94. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement