//File: user32.cs (safe methods)
public static class user32
public static int GetWindowText(int hwnd, ref string lpString, int cch)
return MySolutionSupport.PInvoke.UnsafeNative.user32.GetWindowText(hwnd, ref lpString, cch);
public static int GetWindowTextLength(int hwnd)
return MySolutionSupport.PInvoke.UnsafeNative.user32.GetWindowTextLength(hwnd);
//File: user32.cs (unsafe methods)
[System.Security.SuppressUnmanagedCodeSecurity]
public static class user32
[DllImport("user32.dll", EntryPoint = "GetWindowTextA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
extern public static int GetWindowText(int hwnd, [MarshalAs(UnmanagedType.VBByRefStr)] ref string lpString, int cch);
[DllImport("user32.dll", EntryPoint = "GetWindowTextLengthA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
extern public static int GetWindowTextLength(int hwnd);
private void Command1_Click(Object eventSender, EventArgs eventArgs)
string titleForm1 = new string(Strings.Chr(0), MySolutionSupport.PInvoke.SafeNative.user32.GetWindowTextLength(this.Handle.ToInt32()) + 1);
MySolutionSupport.PInvoke.SafeNative.user32.GetWindowText(this.Handle.ToInt32(), ref titleForm1, Strings.Len(titleForm1));