c#调用c++ dll时,将c++中的char *传给c#,在c#中用StringBuilder,解码后为什么字节数少?
我在c#中调c++ dll 回调函数,
c++:
typedef void (CALLBACK *CBFunc)( char *);
extern "C" __declspec(dllexport) int TCallback(CBFunc pf, char *out)
{
}
c#:
public delegate void OurDllCallBack(StringBuilder iin);
[DllImport("DllCallBackTest.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern void TCallback(OurDllCallBack f, StringBuilder s);
public void ff(StringBuilder s)
{
//将s转为byte[]; 发现转过来的图像数据总是少于640*480*3,什么原因呢?????
}
private void button1_Click(object sender, RoutedEventArgs e)
{
OurDllCallBack fff = new OurDllCallBack(ff);
StringBuilder b = new StringBuilder(640 * 480 * 3);
TCallCDll.TCallback(fff, b);
}
求助,急急!
------解决方案--------------------用IntPtr