2 lihuaijin1989 lihuaijin1989 于 2014.08.25 16:40 提问

VB 调用crc16校验 dll 返回值不正确

真诚求助,其实什么都写好了就是关键时候掉链子了
如下:
C语言写的CRC16 半字节查表 方式校验,dll cpp 程序如下:
unsigned short _stdcall CalCRC16(unsigned char *ptr, unsigned char len)

{

unsigned short crc;

unsigned char da;

unsigned short crc_ta[16]={

0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,

0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef

};

crc =0xFFFF;   
while(len--!=0)    
{   
    da = ((unsigned char)(crc/256))/16;          
    crc<<=4;                                     

crc^=crc_ta[da^(*ptr/16)];

da = ((unsigned char)(crc/256))/16;

crc<<=4;

crc^=crc_ta[da^(*ptr&0x0f)];

ptr++;

}

return(crc);

}

程序没有错误,单独调试OK,单独用函数 输入数组{0xAB,0x05,0x0A}也能返回正确的校验码DF4E

我用VB调用此dll
程序如下:
Private Declare Function CalCRC16 Lib "C:\CRC16.dll\crc16.dll" (ByRef buf() As Byte, ByVal nLen As Long) As Long
Private Sub Command1_Click()
Dim buf(0 To 2) As Byte
buf(0) = &HAB
buf(1) = &H5
buf(2) = &HA
lngCRC = CalCRC16(buf, 3)
Debug.Print Hex(lngCRC)
End Sub
编译OK,但返回值不正确,不知道那里错了,那位大神能告知,不胜感激

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!