public string GetClassName() { unsafe { // The maximum length of a classname is 256. int textLength = 0; byte[] textBuffer = new byte[257 * 2]; fixed(byte *textBufferPtr = textBuffer) { textLength = User32APIs.GetClassNameW(Hwnd, new IntPtr(textBufferPtr), 257); } return(Encoding.Unicode.GetString(textBuffer, 0, textLength * 2)); } }