When I try to use unmanaged code in WPF. e.g. SendMessage(IntPtr hWnd, int Msg, int wParam, ref TOOLINFO toolInfo), this function may return the 0XFFFF for lpszText in TOOLINFO and application crash directly. I have referred MSDN and found that it is a ERROR_ILLEGAL_CHARACTER error. So I want to ask: How can I catch this kind of error in managed code, or how can I return TOOLINFO a good result.
struct TOOLINFO
{
public int cbSize;
public int uFlags;
public IntPtr hwnd;
public IntPtr uId;
public RECT rect;
public IntPtr hinst;
[MarshalAs(UnmanagedType.LPStr)]
public string lpszText;
public IntPtr lParam;
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, ref TOOLINFO toolInfo);