我的测试结果是对的,发了101个,两边都正常
建议COPYDATASTRUCT的lpdata字段用字节数组,字符串在api的参数传递中会进行些转化,默认unicode会转成ansi传递
System.Text.Encoding.Default.GetBytes(this.textBox1.Text);这里得到的是ansi字串长度,对数字而言,长度减半了
byte[] sarr = System.Text.Encoding.Unicode.GetBytes(this.textBox1.Text);
[DllImport("User32.dll",CharSet=CharSet.Unicode, EntryPoint = "SendMessageW")]
[MarshalAs(UnmanagedType.LPWStr)]
public string lpData;
vb
Public Type COPYDATASTRUCT
dwData As Long '结构长度,传lenb(DatrStruct)
cbData As Long '后面指针所指内容的长度,传lenb([字符串])
'lpData As String '声明为一个String,然后直接赋值为字符串变量就行.
lpData as long
End Type
DataStruct.lpData = StrPtr(CtlText)
CopyMemory DatrStruct, ByVal lParam, LenB(DatrStruct)
Dim s As String
s = Space(DatrStruct.cbData \ 2)
CopyMemory ByVal StrPtr(s), ByVal DatrStruct.lpData, DatrStruct.cbData
Form1.Text3 = s