foobar2000 SDK  2015-08-03
clipboard.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 
3 #ifdef _WIN32
4 
5 #ifdef UNICODE
6 #define CF_TCHAR CF_UNICODETEXT
7 #else
8 #define CF_TCHAR CF_TEXT
9 #endif
10 
11 namespace ClipboardHelper {
12  void SetRaw(UINT format,const void * data, t_size size) {
13  HANDLE buffer = GlobalAlloc(GMEM_DDESHARE,size);
14  if (buffer == NULL) throw std::bad_alloc();
15  try {
16  CGlobalLockScope lock(buffer);
17  PFC_ASSERT(lock.GetSize() == size);
18  memcpy(lock.GetPtr(),data,size);
19  } catch(...) {
20  GlobalFree(buffer); throw;
21  }
22 
23  WIN32_OP(SetClipboardData(format,buffer) != NULL);
24  }
25  void SetString(const char * in) {
27  SetRaw(CF_TCHAR,temp.get_ptr(),(temp.length() + 1) * sizeof(TCHAR));
28  }
29 
32  if (!GetRaw(CF_TCHAR,temp)) return false;
33  out = pfc::stringcvt::string_utf8_from_os(reinterpret_cast<const TCHAR*>(temp.get_ptr()),temp.get_size() / sizeof(TCHAR));
34  return true;
35  }
36  bool IsTextAvailable() {
37  return IsClipboardFormatAvailable(CF_TCHAR) == TRUE;
38  }
39 }
40 
41 #endif // _WIN32
const t_item * get_ptr() const
Definition: array.h:213
void * GetPtr() const
Definition: win-objects.h:77
bool GetRaw(UINT format, TArray &out)
Definition: clipboard.h:31
bool IsTextAvailable()
Definition: clipboard.cpp:36
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
string_utf8_from_wide string_utf8_from_os
Definition: string_conv.h:517
size_t t_size
Definition: int_types.h:48
void SetString(const char *in)
Definition: clipboard.cpp:25
const wchar_t * get_ptr() const
Definition: string_conv.h:133
t_size GetSize() const
Definition: win-objects.h:78
bool GetString(pfc::string_base &out)
Definition: clipboard.cpp:30
t_size get_size() const
Definition: array.h:130
void SetRaw(UINT format, const void *data, t_size size)
Definition: clipboard.cpp:12