Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 26th June 2003, 20:18   #1
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
An idea for a function

I was trying to find a way to copy a string to the Windows clipboard using the System plugin, but was unable to find a way (I'm no C++ programmer see!)
I was wondering how this would be achieved?

When I mean "Windows clipboard" I mean so that the user can do a Ctrl+V and the string is copied automatically (without the user doing a Ctrl+C before hand)

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 26th June 2003, 20:40   #2
Joel
Debian user
(Forum King)
 
Joel's Avatar
 
Join Date: Jan 2003
Location: Arch land
Posts: 4,896
In think that there's a "Message" for that:
See in the ${NSISDIR}\Include\WinMessages.nsh


* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux w/ xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Debian unstable w/ xfce4.
Joel is offline   Reply With Quote
Old 26th June 2003, 21:00   #3
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Ah ok.
I have no idea what to do next however...

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 26th June 2003, 21:07   #4
Joel
Debian user
(Forum King)
 
Joel's Avatar
 
Join Date: Jan 2003
Location: Arch land
Posts: 4,896
Maybe with the "SendMessage" use it
But, don't you need to reply that message?


* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux w/ xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Debian unstable w/ xfce4.
Joel is offline   Reply With Quote
Old 26th June 2003, 21:15   #5
brainsucker
Senior Member
 
brainsucker's Avatar
 
Join Date: Sep 2002
Location: Minsk, Belarus
Posts: 190
Send a message via ICQ to brainsucker
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::EmptyClipboard()'
System::Call '*(&t1024 "Just a clipboard demo!") i.r0'
System::Call 'user32::SetClipboardData(i 1, i r0)'
System::Call 'user32::CloseClipboard()'
System::Free $0
brainsucker is offline   Reply With Quote
Old 26th June 2003, 21:46   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Quote:
Originally posted by Lobo Lunar
Maybe with the "SendMessage" use it
But, don't you need to reply that message?
Well duh.
Thanks for the System dll way - that's the kind of way which I was trying to find.

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 26th June 2003, 21:50   #7
Joel
Debian user
(Forum King)
 
Joel's Avatar
 
Join Date: Jan 2003
Location: Arch land
Posts: 4,896
Well...don't blame me for trying


* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux w/ xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Debian unstable w/ xfce4.
Joel is offline   Reply With Quote
Old 26th June 2003, 21:58   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Now, how would I go about getting text from the clipboard into a string

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 26th June 2003, 22:19   #9
brainsucker
Senior Member
 
brainsucker's Avatar
 
Join Date: Sep 2002
Location: Minsk, Belarus
Posts: 190
Send a message via ICQ to brainsucker
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::GetClipboardData(i 1) t .r0'
System::Call 'user32::CloseClipboard()'
brainsucker is offline   Reply With Quote
Old 26th June 2003, 22:31   #10
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,337
brainsucker, according to MSDN you are not supposed to free the memory of the clipboard data, and if allocated it should use GMEM_MOVEABLE. So the code should probably look like this:

StrCpy $0 "string to put in clipboard"
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::EmptyClipboard()'
StrLen $1 $0
System::Call 'kernel32::GlobalAlloc(i 2, i $1) i.r1'
System::Call 'kernel32::lstrcpyA(i $1, t $0)'
System::Call 'user32::SetClipboardData(i 1, i r1)'
System::Call 'user32::CloseClipboard()'

Also, SetClipboardData and CloseClipboard both return a value. Does System.dll default to int return value if nothing is specified?

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 26th June 2003, 22:49   #11
brainsucker
Senior Member
 
brainsucker's Avatar
 
Join Date: Sep 2002
Location: Minsk, Belarus
Posts: 190
Send a message via ICQ to brainsucker
MSDN: The application can read the data, but must not free the handle or leave it locked until the CloseClipboard function is called. (The application can access the data after calling CloseClipboard).
"Can access" could mean 'free', imho.
No considirations about GMEM_MOVEABLE, anyway your way is more correct, but my way works to for strings at least

Functions/Procedures return values in registers, and it doesn't matter how we process it... So if we don't specify return type system plugin just skips the converting step...
brainsucker is offline   Reply With Quote
Old 26th June 2003, 22:56   #12
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,337
MSDN example doesn't free the memory, so I guess we shouldn't too. But it does something else that I have forgotten in my code, it uses GlobalLock. Complete code should be:

StrCpy $0 "string to put in clipboard"
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::EmptyClipboard()'
StrLen $1 $0
System::Call 'kernel32::GlobalAlloc(i 2, i $1) i.r1'
System::Call 'kernel32::GlobalLock(i $1) i.r2'
System::Call 'kernel32::lstrcpyA(i $2, t $0)'
System::Call 'kernel32::GlobalUnlock(i $1)'
System::Call 'user32::SetClipboardData(i 1, i r1)'
System::Call 'user32::CloseClipboard()'

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 27th June 2003, 09:27   #13
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
So, which are the final two scripts?
I'd like to add them to the archive when I get back home...

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 27th June 2003, 11:49   #14
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,337
The last one is the final for copy. The only one that was supposed to be for paste is still the final

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 27th June 2003, 15:25   #15
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Thanks!
http://nsis.sourceforge.net/archive/...ances=0,11,122

-Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 2nd July 2003, 17:20   #16
brainsucker
Senior Member
 
brainsucker's Avatar
 
Join Date: Sep 2002
Location: Minsk, Belarus
Posts: 190
Send a message via ICQ to brainsucker
I've missed some 'tips' in Kichik's script, the right version should look like:


StrCpy $0 "string to put in clipboard"
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::EmptyClipboard()'
StrLen $1 $0
IntOp $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()'


All changes of $n to rn are non fatal, beside the line with lstrcpy,
where $0 shouldn't and couldn't work right.
brainsucker is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump