getClipboardString function

String getClipboardString()

Get the current clipboard as String. Throws a ClipboardException if this fails.

Implementation

String getClipboardString() {
  if (!isClipboardFormatAvailable(1)) {
    throw ClipboardException(ClipboardErrorId.formatNotAvailable);
  }

  if (!openClipboard(null)) {
    throw ClipboardException(ClipboardErrorId.openClipboardError);
  }

  var handle = getClipboardData(1);
  if (handle == nullptr) {
    throw ClipboardException(ClipboardErrorId.nullGetClipboardData);
  }

  var lpstr = globalLock(handle).cast<Utf8>();
  if (lpstr == nullptr) {
    closeClipboard();
    throw ClipboardException(ClipboardErrorId.nullGlobalLock);
  }

  globalUnlock(handle);
  if (!closeClipboard()) {
    throw ClipboardException(ClipboardErrorId.closeClipboardError);
  }
  return Utf8.fromUtf8(lpstr);
}