void AddString(CString a, CString b, CString& c)
{
c = a + b;
}extern "C" void PASCAL EXPORT AddString2(LPCSTR a, LPCSTR b, LPSTR c)
{
CString stra(a);
CString strb(b);
CString strc(c);
AddString(stra,strb,strc);
strcpy(c,strc);
}
本来c#调用的是AddString,但是不能用CString,所以做了一个AddString2。
[DllImport("D:\\Projects\\TestProjects\\TestDLL\\Debug\\TestDLL.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
private unsafe static extern void AddString2(string  x, 
string y,
StringBuilder  z);private void button2_Click(object sender, System.EventArgs e)
{
StringBuilder z = new StringBuilder(256);
string x = textBox3.Text;
string y = textBox4.Text;
AddString2(x,y,z);
textBox6.Text = z.ToString();
}
textBox6.Text怎么得到的是乱码呀?跟踪发现AddString2里面处理的对呀,为何textBox6.Text出来就是乱码了呢?