FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour I have a question. Please help.
Posts: 109
Joined: Sun Nov 13, 2005 12:40 AM
I have a question. Please help.
Posted: Thu Oct 19, 2023 11:49 PM
Hello All.

If you know why this code doesn't work,
please let me know. Did I do something wrong ?

Code (fw): Select all Collapse
#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
FWH User

FWPPC User

FWLinux User
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: I have a question. Please help.
Posted: Fri Oct 20, 2023 08:06 AM

Yes, at least you can't return an unsigned short pointer as a character string and you haven't initialize the pointer itself.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: I have a question. Please help.
Posted: Fri Oct 20, 2023 08:49 AM

Dear Yun,

FWH provides the function nStrCrc( cString ) --> nCrc

also function nFileCrc( cFileName ) --> nCrc

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion