I have a question. Please help.

I have a question. Please help.

Postby yunbg1 » 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: 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

 
FWH User
FWPPC User
FWLinux User
yunbg1
 
Posts: 107
Joined: Sun Nov 13, 2005 12:40 am
Location: Winnipeg Canada

Re: I have a question. Please help.

Postby Enrico Maria Giordano » Fri Oct 20, 2023 8: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.
User avatar
Enrico Maria Giordano
 
Posts: 8718
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: I have a question. Please help.

Postby Antonio Linares » Fri Oct 20, 2023 8:49 am

Dear Yun,

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

also function nFileCrc( cFileName ) --> nCrc
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 70 guests