Skip to content

Conversation

@mhils
Copy link
Contributor

@mhils mhils commented Oct 31, 2015

The Windows method was a bit unstable on my system, so I decided to rewrite it in the most cautious way possible based on the MSDN docs

  • GlobalAlloc is called with GMEM_MOVEABLE as required by SetClipboardData
  • We do the full dance and pass a valid hwnd to OpenClipboard, as required by the SetClipboardData docs
  • If OpenClipboard fails the first time, we repeatedly try to get the clipboard lock for up to 500ms.
  • Fixed support for Python 3.5 x64 (HANDLE apparently as different sizes on x32 and x64, thus we must specify argtypes and restype for each API call)
  • Every Windows API call gets now checked for potential errors
  • Removed .decode('mbcs') call. On Python 2.7, c_wchar_p apparently auto-converts bytes to unicode. On Python 3.5, calling the method with bytes returns a fairly descriptive TypeError: unicode string or integer address expected instead of bytes instanceerror. If there are issues with that, there should be tests to cover this.
  • Given the verbosity, I moved the Windows-specific code in its own file.

This should fix #5, fix #7, fix #10, fix #16, fix #21, fix #25.
It should also fix #27 and #35 by making them obsolete.

@asweigart asweigart merged commit df78c01 into asweigart:master Oct 31, 2015
@asweigart
Copy link
Owner

Thanks a lot for this patch! The problem that's been happening between 32 and 64-bit was one I haven't been able to get to, but this should fix a lot of people's Pyperclip problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants