Hi all,

I'm trying to perform CRC Calculation for a set of byte.
My Transmit Buffer is LPBYTE.

here is my code

Code:
	CRCCalculator objCRCCalculator;
	LPBYTE TransBuf = new BYTE[12];
	TransBuf[0]=0xE1;
	TransBuf[1]=0x80;
	TransBuf[2]=0x01;
	TransBuf[3]=0xE1;
	TransBuf[4]=0xD2;
	TransBuf[5]=0xC3;
	TransBuf[6]=0x00;
	TransBuf[7]=0x00;
	TransBuf[8]=0x00;
	TransBuf[9]=0x00;
	TransBuf[10]=0x00;
	TransBuf[11]=0x00;
	objCRCCalculator.CalculateCRC(TransBuf);




//here is my CRC calculation


unsigned short CRCCalculator::update_crc_16( unsigned short crc, unsigned char  c ) 
{
    unsigned short tmp, short_c;	
    short_c = 0x00ff & (unsigned short)c;
    if ( ! crc_tab16_init )
		init_crc16_tab();
    tmp =  crc       ^ short_c;
    crc = (crc >> 8) ^ crc_tab16[ tmp & 0xff ];   
    return crc;

}  

static void init_crc16_tab( void ) 
{
    int i, j;
    unsigned short crc, c;
    for (i=0; i<256; i++) 
	{
		crc = 0;
        c   = (unsigned short) i;

        for (j=0; j<8; j++)
		{

            if ( (crc ^ c) & 0x0001 )
				crc = ( crc >> 1 ) ^ P_16;
            else                      
				crc =   crc >> 1;
            c = c >> 1;
        }

        crc_tab16[i] = crc;
    }
    crc_tab16_init = TRUE;
}

void CRCCalculator::CalculateCRC(LPBYTE& TxBuf)
{	
	DWORD CRCValue;
	WORD crc_16_modbus  = 0xffff;
	for(int i=0;i<12;i++)
		crc_16_modbus = update_crc_16(crc_16_modbus,TxBuf[i]);	
	CRCValue=crc_16_modbus;
	LPBYTE CRCByte = new BYTE[2];
	CRCByte[0]=HIBYTE(CRCValue);
	CRCByte[1]=LOBYTE(CRCValue);
}
I'm trying to get the CRC value for transmit buffer. but some constant value is overwrite the current values of transmit buffer (TxBuf). I think it is because of passing the LPBYTE by reference. Can anyone tell me how to pass this value? or suggest some way to implement it.

With Thanks & regards,
Saravana