Copy to, or get from Windows Clipboard

From NSIS Wiki

Author: Afrow UK (talk, contrib)


Contents

[edit] Description

Here are two scripts which you may find helpful...

[edit] Copy string to Windows Clipboard

[edit] Usage

Push "hello" ;input > copy to clipboard
Call CopyToClipboard

[edit] The Function

Function CopyToClipboard
Exch $0 ;input string
Push $1
Push $2
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::EmptyClipboard()'
StrLen $1 $0
IntOp $1 $1 + 1
System::Call 'kernel32::GlobalAlloc(i 2, i r1) i.r1'
System::Call 'kernel32::GlobalLock(i r1) i.r2'
System::Call 'kernel32::lstrcpyA(i r2, t r0)'
System::Call 'kernel32::GlobalUnlock(i r1)'
System::Call 'user32::SetClipboardData(i 1, i r1)'
System::Call 'user32::CloseClipboard()'
Pop $2
Pop $1
Pop $0
FunctionEnd

[edit] Copy string from Windows Clipboard

[edit] Usage

Call CopyFromClipboard
Pop $0 ;output > copied from clipboard

[edit] The Function

Function CopyFromClipboard
Push $0
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::GetClipboardData(i 1) t .r0'
System::Call 'user32::CloseClipboard()'
Exch $0
FunctionEnd

Thanks Kichik and Brainsucker for getting these solutions.

-Stu :)

donate
ads