reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 827cffa45b156de60415d724395258a5293ecaca
parent 208c70467e3c67af53d99436fda9cf56819a62a5
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sat, 16 Sep 2017 17:47:48 -0700

dialog: fix clipboard copy on Windows spewing garbage (broken since 76ba324156336015937bf3a27397766c20eac191)

Diffstat:
Msrc/dialog.cpp | 8++------
Msrc/win32.cpp | 12++++++++++++
Msrc/win32.hpp | 1+
3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -18,6 +18,7 @@ #include "dialog.hpp" #include "control.hpp" +#include "win32.hpp" #include <algorithm> #include <boost/range/adaptor/map.hpp> @@ -330,12 +331,7 @@ void Dialog::stopTimer(int id) void Dialog::setClipboard(const string &text) { - // calculate the size in bytes including the null terminator - const size_t size = (text.size() + 1) * sizeof(char); - - HANDLE mem = GlobalAlloc(GMEM_MOVEABLE, size); - memcpy(GlobalLock(mem), text.c_str(), size); - GlobalUnlock(mem); + const HANDLE mem = Win32::globalCopy(text); OpenClipboard(m_handle); EmptyClipboard(); diff --git a/src/win32.cpp b/src/win32.cpp @@ -73,6 +73,18 @@ void Win32::shellExecute(const char *what, const char *arg) ShellExecute(nullptr, L("open"), widen_cstr(what), widen_cstr(arg), nullptr, SW_SHOW); } +HANDLE Win32::globalCopy(const string &text) +{ + // calculate the size in bytes including the null terminator + const size_t size = (text.size() + 1) * sizeof(char_type); + + HANDLE mem = GlobalAlloc(GMEM_MOVEABLE, size); + memcpy(GlobalLock(mem), widen_cstr(text.c_str()), size); + GlobalUnlock(mem); + + return mem; +} + bool Win32::writePrivateProfileString(const char *group, const char *key, const char *value, const char *path) { diff --git a/src/win32.hpp b/src/win32.hpp @@ -55,6 +55,7 @@ namespace Win32 { void setWindowText(HWND handle, const char *text); std::string getWindowText(HWND handle); void shellExecute(const char *what, const char *arg = nullptr); + HANDLE globalCopy(const std::string &); bool writePrivateProfileString(const char *g, const char *k, const char *v, const char *p); std::string getPrivateProfileString(const char *g, const char *k, const char *v, const char *p);