Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to send data to Clipboard using VBScript

Status
Not open for further replies.

LooserFrom

Technical User
May 30, 2012
2
AE
thread329-1654819

Step 1
Go to download dynacall.dll, copy to system32 and register with RegSvr32.

Step 2
From now on you are able to use following Code:

data = "Data that will be placed in clipboard"

const a = 0
const b = 1

'MEMORY ALLOCATION
set c = createobject("dynamicwrapper")
c.register "kernel32.dll", "GlobalAlloc", "i=uu", "f=s", "r=l"
d = c.GlobalAlloc(a, Cint(len(data)+1))
set c = nothing

'LOCK THE MEMORY
set c = createobject("dynamicwrapper")
c.register "kernel32.dll", "GlobalLock", "i=l", "f=s", "r=l"
d = c.GlobalLock(d)
set c = nothing

'COPYING ROWS TO MEMORY
set c = createobject("dynamicwrapper")
c.register "kernel32.dll", "lstrcpy", "i=hs", "f=s", "r=h"
d = c.lstrcpy(d, CStr(data))
set c = nothing

'OPENING CLIPBOARD
set c = createobject("dynamicwrapper")
c.register "user32.dll", "OpenClipboard", "i=h", "f=s", "r=l"
e = c.OpenClipboard(0)
set c = nothing

'CLEARING THE CLIPBOARD
set c = createobject("dynamicwrapper")
c.register "user32.dll", "EmptyClipboard", "f=s", "r=l"
e = c.EmptyClipboard()
set c = nothing

'SETTING THE CLIPBOARD
set c = createobject("dynamicwrapper")
c.register "user32.dll", "SetClipboardData", "i=uh", "f=s", "r=l"
e = c.SetClipboardData(b, d)
set c = nothing

'CLOSURE OF THE CLIPBOARD (RELEASE)
set c = createobject("dynamicwrapper")
c.register "user32.dll", "CloseClipboard", "f=s", "r=l"
e = c.CloseClipboard()
set c = nothing
 
Short form of same script:

data = "Data that will be placed in clipboard"

set a = createobject("dynamicwrapper")
a.register "kernel32.dll", "GlobalAlloc", "i=uu", "f=s", "r=l"
a.register "kernel32.dll", "GlobalLock", "i=l", "f=s", "r=l"
a.register "kernel32.dll", "lstrcpy", "i=hs", "f=s", "r=h"
a.register "user32.dll", "OpenClipboard", "i=h", "f=s", "r=l"
a.register "user32.dll", "EmptyClipboard", "f=s", "r=l"
a.register "user32.dll", "SetClipboardData", "i=uh", "f=s", "r=l"
a.register "user32.dll", "CloseClipboard", "f=s", "r=l"
b = a.lstrcpy(a.GlobalLock(a.GlobalAlloc(0, cint(len(data)+1))), cstr(data))
c = a.OpenClipboard(0)
c = a.EmptyClipboard()
c = a.SetClipboardData(1, b)
c = a.CloseClipboard()
set a = nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top