我是这样写的:[DllImport("C:\\Dcic32.dll")]
private static extern int  IC_Read(int ICDev,int offset,int len,ref byte[] b);
private void button2_Click(object sender, System.EventArgs e)
{
byte[] bb =new byte[8];
IC_Read(i,0,8,ref bb);
}
但还是不行,系统报错:
未处理的“System.NullReferenceException”类型的异常出现在 WindowsApplication1.exe 中。
其他信息: 未将对象引用设置到对象的实例。

解决方案 »

  1.   

    [DllImport("C:\\Dcic32.dll")]
    private static extern int  IC_Read(int ICDev,int offset,int len, byte[] b);
    不要用 ref 。
      

  2.   

    byte[] should work, as long as you allocate memory first:
    byte[] b = new byte[len];
    IC_Read(...., len, b);StringBuilder also works:
    StringBuilder sb = new StringBuilder(len);
    IC_Read(..., len, sb);
      

  3.   

    check :IC_Read(i,0,8,ref bb);i is handle? try:private static extern int  IC_Read(int ICDev,int offset,int len, [MarshalAs(UnmanagedType.LPStr)] ref string b);int i = this.Handle.ToInt32();
    string s = new string('\u0000',9);
    IC_Read (i, 0, 8, ref s);try ref all when after error