summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/lib/osdlib_win32.cpp
diff options
context:
space:
mode:
author npwoods <npwoods@mess.org>2019-09-11 14:16:02 -0400
committer R. Belmont <rb6502@users.noreply.github.com>2019-09-11 14:16:02 -0400
commitbc15184c90a7eaf4cf16ea060916346e390a7c3b (patch)
treebdf475c68602c37cba55338702343f572bbed6ee /src/osd/modules/lib/osdlib_win32.cpp
parent4f8928432a9db8cd46cfd5c6e2cb262eafaed9d2 (diff)
Changed osd_get_clipboard_text() to return std::string (#5615)
* Changed osd_get_clipboard_text() to return std::string This change has only been tested on Windows. The Un*x/Mac versions were made blindly; they might not even build. This needs to be checked prior to merging. * Fixing Mac OS X build (hopefully)
Diffstat (limited to 'src/osd/modules/lib/osdlib_win32.cpp')
-rw-r--r--src/osd/modules/lib/osdlib_win32.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp
index fb4b29e62af..911f95c3bfe 100644
--- a/src/osd/modules/lib/osdlib_win32.cpp
+++ b/src/osd/modules/lib/osdlib_win32.cpp
@@ -134,9 +134,9 @@ void osd_break_into_debugger(const char *message)
// get_clipboard_text_by_format
//============================================================
-static char *get_clipboard_text_by_format(UINT format, std::string (*convert)(LPCVOID data))
+static bool get_clipboard_text_by_format(std::string &result_text, UINT format, std::string (*convert)(LPCVOID data))
{
- char *result = nullptr;
+ bool result = false;
HANDLE data_handle;
LPVOID data;
@@ -155,12 +155,8 @@ static char *get_clipboard_text_by_format(UINT format, std::string (*convert)(LP
if (data != nullptr)
{
// invoke the convert
- std::string s = (*convert)(data);
-
- // copy the string
- result = (char *) malloc(s.size() + 1);
- if (result != nullptr)
- memcpy(result, s.data(), (s.size() + 1) * sizeof(*result));
+ result_text = (*convert)(data);
+ result = true;
// unlock the data
GlobalUnlock(data_handle);
@@ -196,14 +192,16 @@ static std::string convert_ansi(LPCVOID data)
// osd_get_clipboard_text
//============================================================
-char *osd_get_clipboard_text(void)
+std::string osd_get_clipboard_text(void)
{
- // try to access unicode text
- char *result = get_clipboard_text_by_format(CF_UNICODETEXT, convert_wide);
+ std::string result;
- // try to access ANSI text
- if (result == nullptr)
- result = get_clipboard_text_by_format(CF_TEXT, convert_ansi);
+ // try to access unicode text
+ if (!get_clipboard_text_by_format(result, CF_UNICODETEXT, convert_wide))
+ {
+ // try to access ANSI text
+ get_clipboard_text_by_format(result, CF_TEXT, convert_ansi);
+ }
return result;
}