If you know why this code doesn't work,
please let me know. Did I do something wrong ?
- Code: Select all Expand view RUN
#include "FiveWin.ch"
//--------------------------------
FUNC Main()
Test()
RETU NIL
//--------------------------------
FUNC Test()
crc := CRC(chr(5)+chr(1)+chr(251)+chr(20)+chr(2)+chr(3), 6)
msginfo(crc)
RETU NIL
//------------------------------------------------------------------------------
#pragma BEGINDUMP
#include <windows.h>
#include <vfw.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <wininet.h>
#include "tlhelp32.h"
#include "hbvm.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#define BUFMAX 1024
#define MACLEN 6
void get_crc(unsigned char* data, int length, unsigned short* crc) {
int i;
unsigned temp;
unsigned short SEED = 0x8005;
*crc = 0xffff;
do {
temp = *data++ & 0xff;
for (i = 0; i < 8; i++) {
if ((*crc & 0x0001) ^ (temp & 0x01))
*crc = (*crc >> 1) ^ SEED;
else
*crc >>= 1;
temp >>= 1;
}
} while (--length);
*crc = ~*crc;
temp = *crc;
*crc = (*crc << 8) | ((temp >> 8) & 0xff);
return;
}
//----------------------------------------------------------------------------//
HB_FUNC( CRC )
{
int j;
unsigned short SEED = 0x8005;
unsigned short *crc;
char* data = hb_parc(1);
unsigned temp;
int i;
j = hb_parni(2);
*crc = 0xffff;
do {
temp = *data++ & 0xff;
for (i = 0; i < 8; i++) {
if ((*crc & 0x0001) ^ (temp & 0x01))
*crc = (*crc >> 1) ^ SEED;
else
*crc >>= 1;
temp >>= 1;
}
} while (--j);
*crc = ~*crc;
temp = *crc;
*crc = (*crc << 8) | ((temp >> 8) & 0xff);
hb_retc(crc);
}
#pragma ENDDUMP