大家好,有个问题解决不了,请大家帮忙
我从外部引用了一个动态链接库,说明书上写的是可以用VB和VC调用,我现在用C#,有个函数要用到指针,可C#里不能用指针啊,我实在不知道该怎么办了,大家帮忙啊,这是我写的
public class CS200
{
[DllImport("Kmsecs200.dll")]
public static extern int read64_usb(int index,char[] data,int timeout,int readlen);
public char[] read()
{
int rst = 0;
char[] dt = new char[250];
//string dt = null;
try
{
//string aa = null;
//aa = new string;
//MessageBox.Show(aa.Length.ToString());
//int rst = 0;
//string dt=null;
//StringBuilder data = new StringBuilder(250);
//data.Append("dt"); rst = read64_usb(0, dt, 1, 250);
if (rst == 0)
return dt;
else if (rst == -1)
throw new Exception("USB端口序号错误!");
else if (rst == -2)
throw new Exception("管道未打开!");
else if (rst == -3)
throw new Exception("接收错误!");
else return dt;
} catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return dt;
}
finally
{
//end_usb(0);//return null;
}
}
}
说明书上给的例子是
HINSTANCE m_hDll = LoadLibrary("kmsecs200.dll");
USB_IO read64_usb = (USB_IO)GetProcAddress(m_hDll, "read64_usb");
int read64_usb(int Index, char* Dat, int Timeout, int ReadLen)//这句中的接收字符串是个指针
char cBur[250]
read64_usb(0, cBuf, 1, 250);
上面的这句如果在C#中应该怎么写啊
小弟刚来,没有分数,大家关照一下吧
我从外部引用了一个动态链接库,说明书上写的是可以用VB和VC调用,我现在用C#,有个函数要用到指针,可C#里不能用指针啊,我实在不知道该怎么办了,大家帮忙啊,这是我写的
public class CS200
{
[DllImport("Kmsecs200.dll")]
public static extern int read64_usb(int index,char[] data,int timeout,int readlen);
public char[] read()
{
int rst = 0;
char[] dt = new char[250];
//string dt = null;
try
{
//string aa = null;
//aa = new string;
//MessageBox.Show(aa.Length.ToString());
//int rst = 0;
//string dt=null;
//StringBuilder data = new StringBuilder(250);
//data.Append("dt"); rst = read64_usb(0, dt, 1, 250);
if (rst == 0)
return dt;
else if (rst == -1)
throw new Exception("USB端口序号错误!");
else if (rst == -2)
throw new Exception("管道未打开!");
else if (rst == -3)
throw new Exception("接收错误!");
else return dt;
} catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return dt;
}
finally
{
//end_usb(0);//return null;
}
}
}
说明书上给的例子是
HINSTANCE m_hDll = LoadLibrary("kmsecs200.dll");
USB_IO read64_usb = (USB_IO)GetProcAddress(m_hDll, "read64_usb");
int read64_usb(int Index, char* Dat, int Timeout, int ReadLen)//这句中的接收字符串是个指针
char cBur[250]
read64_usb(0, cBuf, 1, 250);
上面的这句如果在C#中应该怎么写啊
小弟刚来,没有分数,大家关照一下吧
int read64_usb(int Index, StringBuilder cBuf , int Timeout, int ReadLen)//如果要复杂的做,就要int read64_usb(int Index,[MarshalAs(UnmanagedType.LPArray)]byte[] cBuf,, int Timeout, int ReadLen)