How do I get the length of a class name in advance so that I can pass it to a parameter nMaxCountin GetClassName()? something like a WM_GETTEXTLENGTHmessage that exists for controls, or does the window class name have a fixed size limit? if so, what is this value?
My goal is the exact size of the passage, not the redistribution method (call GetClassName()until it returns a size smaller than its buffer).
My current implementation (without redistribution method):
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
string GetWindowClass(IntPtr hWnd)
{
const int size = 256;
StringBuilder buffer = new StringBuilder(size + 1);
if (GetClassName(hWnd, buffer, size) == 0)
Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
return buffer.ToString();
}
source
share