Advertisement
expired6978

Untitled

Oct 18th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. class SKSEScaleform_GetClipboardData : public GFxFunctionHandler
  2. {
  3. public:
  4.     virtual void    Invoke(Args * args)
  5.     {
  6.         if (! g_loadGameLock.TryEnter())
  7.             return;
  8.  
  9.         if(OpenClipboard(NULL)) {
  10.             HANDLE cbHandle = NULL;
  11.             LPTSTR textData;
  12.             if(IsClipboardFormatAvailable(CF_TEXT)) {
  13.                 cbHandle = GetClipboardData(CF_TEXT);
  14.                 if(!cbHandle) {
  15.                     CloseClipboard();
  16.                     g_loadGameLock.Leave();
  17.                     return;
  18.                 }
  19.  
  20.                 textData = (LPTSTR)GlobalLock(cbHandle);
  21.                 if(!textData) {
  22.                     CloseClipboard();
  23.                     g_loadGameLock.Leave();
  24.                     return;
  25.                 }
  26.                
  27.                 args->movie->CreateString(args->result, (const char*)textData);
  28.                 GlobalUnlock(cbHandle);
  29.             }
  30.  
  31.             CloseClipboard();
  32.         }
  33.        
  34.         g_loadGameLock.Leave();
  35.     }
  36. };
  37.  
  38. class SKSEScaleform_SetClipboardData : public GFxFunctionHandler
  39. {
  40. public:
  41.     virtual void    Invoke(Args * args)
  42.     {
  43.         if (! g_loadGameLock.TryEnter())
  44.             return;
  45.  
  46.         if(OpenClipboard(NULL)) {
  47.             ASSERT(args->numArgs >= 1);
  48.             ASSERT(args->args[0].GetType() == GFxValue::kType_String);
  49.  
  50.             const char  * clipboardData = args->args[0].GetString();
  51.             UInt32 size = strlen(clipboardData) + 1;
  52.  
  53.             HANDLE handle = GlobalAlloc(GMEM_MOVEABLE, size);
  54.             if(!handle) {
  55.                 CloseClipboard();
  56.                 g_loadGameLock.Leave();
  57.                 return;
  58.             }
  59.             LPTSTR textData = (LPTSTR)GlobalLock(handle);
  60.             if(!textData) {
  61.                 GlobalFree(handle); // Global mem allocated but lock failed
  62.                 CloseClipboard();
  63.                 g_loadGameLock.Leave();
  64.                 return;
  65.             }
  66.  
  67.             memcpy(textData, clipboardData, size);
  68.             GlobalUnlock(handle);
  69.  
  70.             if(!SetClipboardData(CF_TEXT, handle)) {
  71.                 GlobalFree(handle); // Global mem allocated but not used
  72.                 CloseClipboard();
  73.                 g_loadGameLock.Leave();
  74.                 return;
  75.             }
  76.  
  77.             CloseClipboard();
  78.         }
  79.  
  80.         g_loadGameLock.Leave();
  81.     }
  82. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement