[DllImport("user32.dll")]
public static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("User32.dll", CharSet = CharSet.Auto)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int nMaxCount);
int length = GetWindowTextLength(hWnd);
StringBuilder windowName = new StringBuilder(length + 1);
GetWindowText(hWnd, windowName, windowName.Capacity);
用DllImport声明GetWindowText时,千万别跟第2个参数加out。

本文探讨了在C#中使用DllImport声明GetWindowText函数时的常见错误,特别强调了避免在第二个参数上使用out关键字的重要性。

1万+

被折叠的 条评论
为什么被折叠?



