What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Trying to copy some text to the clipboard

Trying to copy some text to the clipboard
Author: Message:
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
O.P. Trying to copy some text to the clipboard
I'm trying to make a function that will copy text to the clipboard. I'm using the Windows API. This is the code I have so far:

code:
function set_clipboard_text()
{
    var tmp = "This is a test";
    var l = tmp.length * 2 + 2;

    if (Interop.Call("User32", "OpenClipboard", 0))
    {
            Interop.Call("User32", "EmptyClipboard");
            var h = Interop.Call("Kernel32", "GlobalAlloc", 0x2000, l);
            var p = Interop.Allocate( l );
            p.WriteDWORD(0, Interop.Call("Kernel32", "GlobalLock", h));
            Interop.Call("Kernel32", "lstrcpyW", p, tmp);
            Interop.Call("Kernel32", "GlobalUnlock", h);
            Interop.Call("User32", "SetClipboardData", 1, h)
            Interop.Call("User32", "CloseClipboard");
    }
}


I'm obviously going to make it set_clipboard_text(str), the way the function is now is just while I test it and try and get it to work.

I'm basing it off some C++ code that I wrote a while ago:

code:
    OpenClipboard(NULL);
    EmptyClipboard();
    HGLOBAL h = GlobalAlloc(GMEM_DDESHARE, strlen(source)+1);
    char* p = (char*)GlobalLock( h );
    lstrcpy(p, source);
    GlobalUnlock( h );
    SetClipboardData(CF_TEXT,h);
    CloseClipboard();


The function as it is now works fine, there are no errors. And text is copied to the clipboard. The problem is, this text consists of several spaces and random characters. I have a feeling it's a unicode problem but I can't see where I've gone wrong in my function, so does anyone have any ideas?
The previous sentence is false. The following sentence is true.
07-07-2006 04:27 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Trying to copy some text to the clipboard - by segosa on 07-07-2006 at 04:27 PM
RE: Trying to copy some text to the clipboard - by J-Thread on 07-07-2006 at 10:48 PM
RE: Trying to copy some text to the clipboard - by RaceProUK on 07-07-2006 at 10:55 PM
RE: Trying to copy some text to the clipboard - by J-Thread on 07-07-2006 at 11:00 PM
RE: Trying to copy some text to the clipboard - by Dhaya on 07-07-2006 at 11:28 PM
RE: Trying to copy some text to the clipboard - by Eljay on 07-08-2006 at 07:43 AM
RE: Trying to copy some text to the clipboard - by J-Thread on 07-08-2006 at 11:02 AM
RE: Trying to copy some text to the clipboard - by andrey on 07-12-2006 at 02:26 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On