当前位置: 代码迷 >> PB >> pb10读取二进制文件的困惑
  详细解决方案

pb10读取二进制文件的困惑

热度:89   发布时间:2016-04-29 06:22:00.0
pb10读取二进制文件的疑惑
小弟需要在pb中调用c的api函数,因此需要将一个二进制文件的内容读取到char数组中,使用了一下代码
Integer li_filenum
Long flen, bytes_read
Blob b, tot_b, b1
char ch

flen = FileLength("hardware.bin")

li_filenum = FileOpen("hardware.bin",streammode!, Read!, lockread!)
 
bytes_read = FileRead(li_filenum, b)
 
FileClose(li_filenum)

char exeFileBuf[]=space(flen)
int test[1024]

For i = 1 To Len(b)
 b1 = BlobMid(b,i,1)
 ch=char(b1)
test[i]=asc(ch)      //这个数组是调试测试使用
Next

每次调试的结果是,文件能打开,大小可以获取,但是test数组全部元素都为0,小弟不知道是读取文件时出错了,还是blob转换为char[]时出错了,敬请赐教
另外,这段代码在pb8上可以正常运行
------解决方案--------------------
写错了,应该是b1 
test[i]=asca(string(b1,encodingansi!)) //
  相关解决方案