MCPcopy Create free account
hub / github.com/SFML/SFML / setString

Method setString

src/SFML/Window/Win32/ClipboardImpl.cpp:79–105  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

77
78////////////////////////////////////////////////////////////
79void ClipboardImpl::setString(const String& text)
80{
81 if (!OpenClipboard(nullptr))
82 {
83 err() << "Failed to open the Win32 clipboard: " << getErrorString(GetLastError()) << std::endl;
84 return;
85 }
86
87 if (!EmptyClipboard())
88 {
89 err() << "Failed to empty the Win32 clipboard: " << getErrorString(GetLastError()) << std::endl;
90 CloseClipboard();
91 return;
92 }
93
94 // Create a Win32-compatible string
95 const auto string = text.toUtf16();
96 const std::size_t stringSize = (string.size() + 1) * sizeof(char16_t);
97 if (const HANDLE stringHandle = GlobalAlloc(GMEM_MOVEABLE, stringSize))
98 {
99 std::memcpy(GlobalLock(stringHandle), string.data(), stringSize);
100 GlobalUnlock(stringHandle);
101 SetClipboardData(CF_UNICODETEXT, stringHandle);
102 }
103
104 CloseClipboard();
105}
106
107} // namespace sf::priv

Callers

nothing calls this directly

Calls 2

getErrorStringFunction · 0.85
toUtf16Method · 0.80

Tested by

no test coverage detected