I want to get the class title of a window which owns the primary clipboard in X Window system.

I have the following code:

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>

main(int argc, char **argv)
Atom real;
unsigned char *data;
int format;
ulong n, extra;

  Display *dpy = XOpenDisplay(NULL);

  // Get the selection window
 Window window = XGetSelectionOwner(dpy, XA_PRIMARY);
printf("%d\n", (unsigned)window);

 XGetWindowProperty(dpy,  window, XA_WM_NAME, 0, ~0, False,
                        AnyPropertyType, &real, &format, &n, &extra,
                        &data) ;

  //    char *wm_class2 = data + strlen(data) + 1;
  printf("%s\n", data);
 // printf("%s\n", wm_class2);
return 0;
While it works for XA_WM_NAME, it fails for XA_WM_CLASS. Would you please tell me what's wrong with it?