Функция не работает...
A call to PInvoke function 'Testing-Class!Testing_Class.Form1::GetClassName' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
Что я уже пробовал:
Я должен добавить это
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern long GetClassName(IntPtr hwnd, StringBuilder lpClassName, long nMaxCount);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern long GetWindowText(IntPtr hwnd, StringBuilder lpString, long cch);
string GetCaptionOfWindow(IntPtr hwnd) { string caption = ""; StringBuilder windowText = null; try { int max_length = GetWindowTextLength(hwnd); windowText = new StringBuilder("", max_length + 5); GetWindowText(hwnd, windowText, max_length + 2); // Its is giving error here if (!String.IsNullOrEmpty(windowText.ToString()) && !String.IsNullOrWhiteSpace(windowText.ToString())) caption = windowText.ToString(); } catch (Exception ex) { caption = ex.Message; } finally { windowText = null; } return caption; } string GetClassNameOfWindow(IntPtr hwnd) { string className = ""; StringBuilder classText = null; try { int cls_max_length = 1000; classText = new StringBuilder("", cls_max_length + 5); GetClassName(hwnd, classText, cls_max_length + 2);// Its is giving error here if (!String.IsNullOrEmpty(classText.ToString()) && !String.IsNullOrWhiteSpace(classText.ToString())) className = classText.ToString(); } catch (Exception ex) { className = ex.Message; } finally { classText = null; } return className; }