locked
GetClassName buffer length RRS feed

  • Question

  • How can I find out length of string of WindowClassName ?

    I need it because I want to use GetClassName function and it need buffer with specified length.

    Friday, April 27, 2007 7:36 AM

All replies

  • You don't need to know it. Just make sure you use a buffer big enough.

    Specifies the length, in TCHAR, of the buffer pointed to by the lpClassName parameter. The class name string is truncated if it is longer than the buffer and is always null-terminated.

     

    Friday, April 27, 2007 8:52 AM
  • I know this, but I need to read not truncated class name.

    I know that I can do this with resizing buffer until GetClassName returns smaller number then is size of buffer. I want to avoid this solution due to performance of reallocation.

    Is it true that window class name is atom? And max atom size is 255 chars. 

    Friday, April 27, 2007 11:42 AM
  • So what's the final answer? :)

    I just need to do the same and I do not want to guess about the size of the buffer that needs to be passed to the function GetClassName.

    Monday, August 10, 2020 10:03 AM
  • The maximum length is documented at https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-wndclassa

    lpszClassName

    ......

    The maximum length for lpszClassName is 256. If lpszClassName is greater than the maximum length, the RegisterClass function will fail.




    • Edited by RLWA32 Monday, August 10, 2020 10:23 AM
    Monday, August 10, 2020 10:23 AM
  • Thank you!
    Monday, August 10, 2020 10:25 AM
  • So what's the final answer? :)

    I just need to do the same and I do not want to guess about the size of the buffer that needs to be passed to the function GetClassName.

    GetClassName calls GetAtomName

    and MSDN says at String Atoms :

    The string associated with a string atom can be no more than 255 bytes in size. This limitation applies to all atom functions.

    Monday, August 10, 2020 10:26 AM
  • I'll guess that the figure of 256 includes the null terminator.

    Monday, August 10, 2020 10:27 AM