在我的应用程序中,我正在阅读同一进程的窗口文本。我正在使用 User32.dll 的 GetWindowText。但是当它尝试调用该方法时,我收到异常“在 aaaa.exe 中发生'System.ExecutionEngineException' 类型的未处理异常”。我在哪里可以看到确切的错误。以及为什么我得到这个例外。
我的代码如下。
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetWindowText(IntPtr hWnd,
[Out] StringBuilder lpString, int nMaxCount);
EnumDelegate enumfunc = new EnumDelegate(EnumWindowsProc);
private bool EnumWindowsProc(IntPtr win, int lParam)
{
StringBuilder sb = new StringBuilder();
GetWindowText(win, sb, 100);
if (sb.Length > 0)
{
// do something
}
}