mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
Retrieve Windows error message on clipboard failures
This commit is contained in:
parent
658176879a
commit
e39f48742b
@ -31,6 +31,21 @@
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string getErrorString(DWORD error)
|
||||
{
|
||||
PTCHAR buffer;
|
||||
|
||||
if (FormatMessage(FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, reinterpret_cast<PTCHAR>(&buffer), 0, NULL) == 0)
|
||||
return "Unknown error.";
|
||||
|
||||
sf::String message = buffer;
|
||||
LocalFree(buffer);
|
||||
return message.toAnsiString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
@ -43,13 +58,13 @@ String ClipboardImpl::getString()
|
||||
|
||||
if (!IsClipboardFormatAvailable(CF_UNICODETEXT))
|
||||
{
|
||||
err() << "Failed to get the clipboard data in Unicode format." << std::endl;
|
||||
err() << "Failed to get the clipboard data in Unicode format: " << getErrorString(GetLastError()) << std::endl;
|
||||
return text;
|
||||
}
|
||||
|
||||
if (!OpenClipboard(NULL))
|
||||
{
|
||||
err() << "Failed to open the Win32 clipboard." << std::endl;
|
||||
err() << "Failed to open the Win32 clipboard: " << getErrorString(GetLastError()) << std::endl;
|
||||
return text;
|
||||
}
|
||||
|
||||
@ -57,7 +72,7 @@ String ClipboardImpl::getString()
|
||||
|
||||
if (!clipboard_handle)
|
||||
{
|
||||
err() << "Failed to get Win32 handle for clipboard content." << std::endl;
|
||||
err() << "Failed to get Win32 handle for clipboard content: " << getErrorString(GetLastError()) << std::endl;
|
||||
CloseClipboard();
|
||||
return text;
|
||||
}
|
||||
@ -75,13 +90,13 @@ void ClipboardImpl::setString(const String& text)
|
||||
{
|
||||
if (!OpenClipboard(NULL))
|
||||
{
|
||||
err() << "Failed to open the Win32 clipboard." << std::endl;
|
||||
err() << "Failed to open the Win32 clipboard: " << getErrorString(GetLastError()) << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EmptyClipboard())
|
||||
{
|
||||
err() << "Failed to empty the Win32 clipboard." << std::endl;
|
||||
err() << "Failed to empty the Win32 clipboard: " << getErrorString(GetLastError()) << std::endl;
|
||||
CloseClipboard();
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user