win32clipboard.GetClipboardData() return string with null characters

Discussion in 'Python' started by aurora, May 26, 2005.

  1. aurora

    aurora Guest

    I was using win32clipboard.GetClipboardData() to retrieve the Windows
    clipboard using code similar to the message below:

    http://groups-beta.google.com/group/comp.lang.python/msg/3722ba3afb209314?hl=en

    Some how I notice the data returned includes \0 and some characters that
    shouldn't be there after the null character. It is easy enough to truncate
    them. But why does it get there in the first place? Is the data length
    somehow calculated wrong?

    I'm using Windows XP SP2 with Python 2.4 and pywin32-203.

    aurora
    aurora, May 26, 2005
    #1
    1. Advertising

  2. aurora

    Roger Upole Guest

    I don't get any extra characters. Do they always show up, or is it possible
    whatever application put the data on the clipboard put them there ?

    Roger
    ..
    "aurora" <> wrote in message news:eek:...
    >I was using win32clipboard.GetClipboardData() to retrieve the Windows clipboard using code similar to the message below:
    >
    > http://groups-beta.google.com/group/comp.lang.python/msg/3722ba3afb209314?hl=en
    >
    > Some how I notice the data returned includes \0 and some characters that shouldn't be there after the null character. It is
    > easy enough to truncate them. But why does it get there in the first place? Is the data length somehow calculated wrong?
    >
    > I'm using Windows XP SP2 with Python 2.4 and pywin32-203.
    >
    > aurora





    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= East/West-Coast Server Farms - Total Privacy via Encryption =---
    Roger Upole, May 26, 2005
    #2
    1. Advertising

  3. aurora

    Guest

    It appears to me that some applications put extra garbage data into the
    clipboard. win32clipboard may have faithfully returning all of them.

    I use this application to show the clipboard content:



    import win32clipboard, win32con
    def getWinClipboardText():
    win32clipboard.OpenClipboard()
    d=win32clipboard.GetClipboardData(win32con.CF_TEXT)
    win32clipboard.CloseClipboard()
    return d

    print getWinClipboardText().encode('string_escape')



    For example, copying the Python banner from the windows console gets me
    this output. Notice the \x00 and garbage characters after that.

    ----------------------------------------------------------
    Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
    on win32\r\nType "help", "copyright", "credits" or "lic
    ense" for more information.\x00\n ??
    ----------------------------------------------------------


    Some applications appear to put clean data in the clipboard always:
    Opera, Putty, Outlook

    Some applications appear to include \0 and other crap:
    cmd.exe, powerpoint, EmEditor.exe

    When I paste, it never appears to be any problem that there maybe
    garbage characters in the clipboard. Guess most C based program
    correctly null terminates the string.
    , May 26, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Trader
    Replies:
    2
    Views:
    326
    Trader
    Aug 26, 2003
  2. Kyle Harrigan

    GetClipboardData(CF_BITMAP) unimplemented

    Kyle Harrigan, May 20, 2004, in forum: Python
    Replies:
    3
    Views:
    2,426
    Michel Claveau/Hamster
    May 21, 2004
  3. Tim Golden
    Replies:
    1
    Views:
    789
    Michel Claveau/Hamster
    May 22, 2004
  4. LeeRisq

    win32clipboard operation

    LeeRisq, Jul 23, 2009, in forum: Python
    Replies:
    4
    Views:
    273
    LeeRisq
    Jul 23, 2009
  5. Replies:
    16
    Views:
    195
    Dave Angel
    Sep 19, 2013
Loading...

Share This Page