In my application, I am reading the text of a window for the same process. I am using GetWindowText of User32.dll. But when it tries to call the method, I am getting the exception "An unhandled exception of type 'System.ExecutionEngineException' occurred in aaaa.exe". Where can I see the exact error. And why I am getting this exception.
My code is as below.
[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
}
}