指针的问题!!!!!!
我遇到一个问题,详细代码如下:
[DllImport("LClientDll.dll",EntryPoint="LClientStartDemo",ExactSpelling=false,CallingConvention=CallingConvention.Cdecl)]
public static extern unsafe int LClientStartDemo(string host, string port, string oper, string ch, int flag);
[DllImport("LClientDll.dll",EntryPoint="LClientRcvDemo",ExactSpelling=false,CallingConvention=CallingConvention.Cdecl)]
public static extern unsafe int LClientRcvDemo(char *data);
[DllImport("LClientDll.dll",EntryPoint="LClientStop",ExactSpelling=false,CallingConvention=CallingConvention.Cdecl)]
public static extern int LClientStop();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int r = LClientStartDemo("127.0.0.1", "7628", "801", "0", 0);
}
LClientRcvDemo(char *data)参数是指针我希望将值传递给一个变量然后进行进一步处理方案可行吗?具体如何操作?
[解决办法]
[DllImport("LClientDll.dll")]
public static extern int LClientStartDemo(string host, string port, string oper, string ch, int flag);
[DllImport("LClientDll.dll")]
public static extern int LClientRcvDemo(StringBuilder sb);
private void button1_Click(object sender, EventArgs e)
{
int r = LClientStartDemo("127.0.0.1", "7628", "801", "0", 0);
while (true)
{
StringBuilder str = new StringBuilder(100);
r = LClientRcvDemo(str);
Console.WriteLine("r={0}", r);
if (r == -100) continue;
if (r > 0)
{
MessageBox.Show(string.Format("r={0} data=[{1}]", r, str));
}
else
{
MessageBox.Show(string.Format("r={0} restart...", r));
break;
}
}
}