You should allocate memory within the StringBuilder
instance:
StringBuilder WindowTitleText = new StringBuilder();
int size = 256;
WindowTitleText.Length = size; // <- Memory allocation
// Read text into allocated memory
GetWindowText(WindowTitleTextPtr, WindowTitleText, WindowTitleText.Length);