Here you go, only tested once (~26KB) :- EDIT: LINK REMOVED.
Code:
ClipBoard_GetText()
Returns:-
Int,
-1: ANSI text not available on ClipBoard
-2: Cannot Open Clipboard
-3: Cannot get ClipBoard data
-4: Lock ClipBoard memory failed
Else, ANSI TEXT String from ClipBoard.
Code:
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <windows.h>
//#include <stdio.h>
#include "avisynth.h" // Avisynth VERSION 3 HEADER (Avisynth v2.58)
AVSValue __cdecl Clipboard_GetText(AVSValue args, void* user_data, IScriptEnvironment* env) {
AVSValue Ret = -1; // Preset "ANSI text not available on ClipBoard"
// BOOL IsClipboardFormatAvailable(UINT format); // format = clipboard format
if(IsClipboardFormatAvailable(CF_TEXT) != 0) {
Ret = -2; // Preset "Cannot Open Clipboard"
// BOOL OpenClipboard(HWND hWndNewOwner) // hWndNewOwner = handle to window, NULL = the current task
if(OpenClipboard(NULL) != 0) {
Ret = -3; // Preset "Cannot get ClipBoard data"
// Obtain the handle to the global memory block that is referencing the text.
// HANDLE GetClipboardData(UINT uFormat); // uFormat = clipboard format
HANDLE hData = GetClipboardData(CF_TEXT);
if(hData != NULL) {
Ret = -4; // Preset, Lock ClipBoard memory failed.
// Lock Clipboard memory so you can reference the actual data string.
// LPVOID GlobalLock(HGLOBAL hMem); // hMem = handle to global memory object.
LPVOID lpClip = GlobalLock(hData);
if(lpClip != NULL) {
Ret = env->SaveString((char*)lpClip); // Save String and return as AVSValue to Avisynth (SUCCESS).
// BOOL GlobalUnlock(HGLOBAL hMem); // hMem = handle to global memory object
GlobalUnlock(hData); // return 0 on FAIL (???)
}
}
CloseClipboard(); // 0 = FAIL (???)
}
}
return Ret;
}
extern "C" __declspec(dllexport) const char* __stdcall AvisynthPluginInit2(IScriptEnvironment* env) {
env->AddFunction("Clipboard_GetText", "",Clipboard_GetText, 0);
return "`Clipboard' Clipboard plugin";
}
EDIT: ANSI text ONLY.
EDIT: Test script (Copy entire script to clipboard before execute: EDIT: CTRL/A then CTRL/C)
Code:
S=ClipBoard_GetText()
RT_DebugF("%s",String(S),name="ClipBoard TEST: ")
Return MessageClip("OK")
Result in DebugView
Code:
00000004 22:19:36 ClipBoard TEST: S=ClipBoard_GetText()
00000005 22:19:36 ClipBoard TEST:
00000006 22:19:36 ClipBoard TEST: RT_DebugF("%s",String(S),name="ClipBoard TEST: ")
00000007 22:19:36 ClipBoard TEST:
00000008 22:19:36 ClipBoard TEST: Return MessageClip("OK")
00000009 22:19:36 ClipBoard TEST:
EDIT: Would ClipBoard_PutText() And/Or ClipBoard_ClearText() be of use ?