Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / C++

CRC_32

Rate me:
Please Sign up or sign in to vote.
4.50/5 (9 votes)
9 Oct 2001CPOL3 min read 148.6K   5.5K   55  
A class that implements the CRC-32 Cyclic Redundancy Check Algorithm (MultiThreaded with Progress Bar support)
/****************************************************************************
CRC_32.h : header file for the CRC_32 class
written by PJ Arends
pja@telus.net

based on the CRC-32 code found at
http://www.createwindow.com/programming/crc32/crcfile.htm

For updates check http://www3.telus.net/pja/crc32.htm

-----------------------------------------------------------------------------
This code is provided as is, with no warranty as to it's suitability or usefulness
in any application in which it may be used. This code has not been tested for
UNICODE builds, nor has it been tested on a network ( with UNC paths ).

This code may be used in any way you desire. This file may be redistributed by any
means as long as it is not sold for profit, and providing that this notice and the
authors name are included.

If any bugs are found and fixed, a note to the author explaining the problem and
fix would be nice.
-----------------------------------------------------------------------------
****************************************************************************/

#ifndef _CRC_32_H_EA6C0EE0_BC30_11d5_B625_A58C4DF45B22_INCLUDED
#define _CRC_32_H_EA6C0EE0_BC30_11d5_B625_A58C4DF45B22_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef _WINDOWS_
#include <windows.h>
#endif // _WINDOWS_

#define WM_CRC_THREAD_DONE WM_APP + 0x2DB1

class CRC_32
{
    typedef struct tag_CRCStruct
    {
        CRC_32 *pCRC_32;
        TCHAR FileName[_MAX_PATH];
        LPBYTE pByte;
        UINT size;
        HWND hWnd;
        HANDLE Thread;
    } CRCStruct, *LPCRCStruct;

public:
    CRC_32();
    DWORD CalcCRC(LPCTSTR FileName, HWND ProgressWnd = NULL);
    DWORD CalcCRC(LPVOID buffer, UINT size, HWND ProgressWnd = NULL);

private:
    static DWORD WINAPI CRC32ThreadProc(LPVOID lpVoid);
    void Calculate (const LPBYTE buffer, UINT size, ULONG &crc);
    ULONG Reflect(ULONG ref, char ch);
    ULONG Table[256];
};

#endif // _CRC_32_H_EA6C0EE0_BC30_11d5_B625_A58C4DF45B22_INCLUDED

/////////////////////////////////////////////////////////////////////////////
//
//  End of CRC_32.h
//
/////////////////////////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
President
Canada Canada
Father of two, brother of two, child of two.
Spouse to one, uncle to many, friend to lots.
Farmer, carpenter, mechanic, electrician, but definitely not a plumber.
Likes walks with the wife, board games, card games, travel, and camping in the summer.
High school graduate, college drop-out.
Hobby programmer who knows C++ with MFC and the STL.
Has dabbled with BASIC, Pascal, Fortran, COBOL, C#, SQL, ASM, and HTML.
Realized long ago that programming is fun when there is nobody pressuring you with schedules and timelines.

Comments and Discussions