byte[]  ant = new byte[1000]在函数的传递,要将返回值写入 ant,
引用的是外部dlla (ref ant) 得不到数据
a(ref ant[0]) 确得到了所有数据,并且 ant被写满了这是为什么呢

解决方案 »

  1.   

    byte[] ant = new byte[1000]
    这是什么语言的语法?delphi和c++这种语法都不对?看起来像是c++,是c#么?c#不太懂,如果是c++的话应该是 byte* ant = new byte[1000]或者byte ant[1000]
    ant数组一定是有数据的,因为已经new过了,都是野数据,不可能得不到数据,但数据正不正确就看你怎么写的函数了,你贴的代码太少了。
      

  2.   

    第一 是c#语法
    第二 ant里不是野数据,是正常获得的数据
      

  3.   

    哦,那个a函数具体也没代码,所以不好说为什么a (ref ant)没得到数据而a(ref ant[0]) 得到正确数据了,应该是a那个函数的实现有问题,对于数组传递,例如
    void a(byte* ant) //a函数
    {
       ant[0]=...;
       ant[1]=...;
       ...
       ant[1000]=...;
    }byte* ant=new byte[1000];
    ZeroMemory(ant,1000);//最好先用0填充,避免有野数据a(ant);
    a(&ant[0]);这两种方式没有区别,因为数组就是指针,指向数组的第一个元素
      

  4.   

    多谢,我也不太清楚为什么会这样,这是由c++ dll 封装而来int __stdcall WriteTagMem(void *hreader, int protocol,int antid, unsigned char *tagid,int tagidlength, int bank,int stblk, int blkcnt, unsigned char *bytesbuf);以上是原形