How to make ClipboardCopy work?

I have tried many variation of the following code, none of which worked for me, meaning nothing gets copied to the Clipboard. My goal is to copy something from the game (a string) into the clipboard.

// Fill out your copyright notice in the Description page of Project Settings.

#include "GenericPlatform/GenericPlatformApplicationMisc.h"
#include "Clipboarduwu.h"

FString UClipboarduwu::happay(FString s)
{
  TCHAR tc[100];
  char txtToCopy[11] = "hellohello";
  for (int i = 0; i <= strlen(txtToCopy); i++)
  {
    tc[i] = txtToCopy[i];
  }
  FGenericPlatformApplicationMisc::ClipboardCopy(tc);
  return tc;
}

The above code compiles and links fine, BUT it does not copy anything into the clipboard.

I have tried the non-generic version but it would not compile, or it would not recognize the header.

Please, can you help me understand what I am doing wrong?

I know the code runs, because I can see the returned value (“hellohello”) in game when calling it, but the clipboard remains untouched.

Thank you!

1 Like

Try this.

Change this

#include "GenericPlatform/GenericPlatformApplicationMisc.h"

To this.

#include "HAL/PlatformApplicationMisc.h"

And, Change this

 FGenericPlatformApplicationMisc::ClipboardCopy(tc);

To this.

FPlatformApplicationMisc::ClipboardCopy(tc);

I stepped into the same trap.

4 Likes