Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SKSEScaleform_GetClipboardData : public GFxFunctionHandler
- {
- public:
- virtual void Invoke(Args * args)
- {
- if (! g_loadGameLock.TryEnter())
- return;
- if(OpenClipboard(NULL))
- {
- BOOL unicode = IsClipboardFormatAvailable(CF_UNICODETEXT);
- BOOL utf8 = IsClipboardFormatAvailable(CF_TEXT);
- if(unicode || utf8)
- {
- HANDLE handle = GetClipboardData(unicode ? CF_UNICODETEXT : CF_TEXT);
- if(handle)
- {
- LPTSTR textData = (LPTSTR)GlobalLock(handle);
- if(textData)
- {
- if(unicode)
- args->movie->CreateWideString(args->result, (const wchar_t*)textData);
- else
- args->movie->CreateString(args->result, (const char*)textData);
- GlobalUnlock(handle);
- }
- }
- }
- CloseClipboard();
- }
- g_loadGameLock.Leave();
- }
- };
- class SKSEScaleform_SetClipboardData : public GFxFunctionHandler
- {
- public:
- virtual void Invoke(Args * args)
- {
- if(!g_loadGameLock.TryEnter())
- return;
- if(OpenClipboard(NULL))
- {
- const wchar_t * textUnicode = args->args[0].GetWideString();
- const char * textUtf8 = args->args[0].GetString();
- void * textIn = NULL;
- UInt32 size = 0;
- if(textUnicode) {
- size = (wcslen(textUnicode) + 1) * sizeof(wchar_t);
- textIn = (void*)textUnicode;
- }
- else if(textUtf8) {
- size = strlen(textUtf8) + 1;
- textIn = (void*)textUtf8;
- }
- if(textIn && size > 0)
- {
- HANDLE handle = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, size);
- if(handle)
- {
- LPTSTR textData = (LPTSTR)GlobalLock(handle);
- if(textData)
- {
- memcpy(textData, textIn, size);
- GlobalUnlock(handle);
- EmptyClipboard();
- if(SetClipboardData(textUtf8 ? CF_TEXT : CF_UNICODETEXT, handle))
- {
- handle = NULL; // ownership passed to the OS
- }
- }
- // clean up the allocation if something failed
- if(handle)
- {
- GlobalFree(handle);
- }
- }
- }
- CloseClipboard();
- }
- g_loadGameLock.Leave();
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement