[DllImport("user32.dll", EntryPoint="GetWindowText")]
public static extern int GetWindowText (
int hwnd,
string lpString,
int cch
);为什么第二个参数用string的话没有效果(不改变原来lpString的值)
改为StringBuilder就可以可以了?
public static extern int GetWindowText (
int hwnd,
string lpString,
int cch
);为什么第二个参数用string的话没有效果(不改变原来lpString的值)
改为StringBuilder就可以可以了?
private void button1_Click(object sender, System.EventArgs e)
{
STRINGBUFFER s;
GetWindowText(button1.Handle, out s, 256);
MessageBox.Show(s.szText);
}
[DllImport("user32.dll", EntryPoint="GetWindowText")]
public static extern int GetWindowText (
IntPtr hwnd,
out STRINGBUFFER lpString,
int cch
);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct STRINGBUFFER
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
public string szText;
}