FastCRC Library API

FastCRC Library Run-Time Dynamic Linking

In order to perform run-time dynamic linking to FastCRC.dll, follow these steps:

  1. Call Windows API LoadLibrary function passing the name of the library ( "FastCRC.dll" ). The function returns the handle to loaded DLL.
  2. Call Windows API GetProcAddress function passing the handle received in Step 1 and the index of the function you want to use.  GetProcAddress returns the pointer to the specified function. The corresponding indices for each function from FastCRC.dll are listed here.
  3. Repeat Step 2 for all functions you need to use.
  4. Call the function(s) through the pointer(s) received in Step 2.
  5. At the end call Windows API FreeLibrary function passing the handle received in Step 1.

Example

#include <stdio.h>
#include <string.h>
#include <windows.h>

/* All function indices in FastCRC.dll can be found in:*/
/* FastCRC Library Help (FastCRC Library Run-Time Dynamic Linking page) */
#define CRC32_INIT_INDEX          101
#define CRC32_UPDATE_INDEX        102
#define CRC32_FINAL_INDEX         104
#define CRC32_CALCULATE_INDEX     105

#define FCRC_CONVERTTOHEX32_INDEX 51

/* This constant can be found in FastCRC.h */
#define FCRC_MAXHEXSIZE           9

/* Declare pointer types for each function you need to use */
typedef void          ( _stdcall *PINIT )( unsigned long* );
typedef void          ( _stdcall *PUPDATE )( unsigned long*, const void*, unsigned int );
typedef unsigned long ( _stdcall *PFINAL )( unsigned long* );
typedef unsigned long ( _stdcall *PCALCULATE )( const void*, unsigned int );

typedef void          ( _stdcall *PCONVERTTOHEX32 )( char*, unsigned long, int );

int main()
{
    PINIT           pInit;
    PUPDATE         pUpdate;
    PFINAL          pFinal;
    PCALCULATE      pCalculate;

    PCONVERTTOHEX32 pConvertToHex32;

    char buff[ 256 ];

    unsigned long checksum;
    char          checksumhex[ FCRC_MAXHEXSIZE ]; /*0 terminated*/

    unsigned long crcvar;

    /*****Load FastCRC.dll*************/
    HMODULE hModule = LoadLibrary( "FastCRC.dll" );
    if( !hModule )
    {
        printf( "Could not load FastCRC.dll library" );
        return 1;
    }

    /*****Get all function addresses*****/
    pInit           = (PINIT)GetProcAddress( hModule, (LPCSTR)CRC32_INIT_INDEX );
    pUpdate         = (PUPDATE)GetProcAddress( hModule, (LPCSTR)CRC32_UPDATE_INDEX );
    pFinal          = (PFINAL)GetProcAddress( hModule, (LPCSTR)CRC32_FINAL_INDEX );
    pCalculate      = (PCALCULATE)GetProcAddress( hModule, (LPCSTR)CRC32_CALCULATE_INDEX );

    pConvertToHex32 = (PCONVERTTOHEX32)GetProcAddress( hModule, (LPCSTR)FCRC_CONVERTTOHEX32_INDEX );

    do
    {
        /*****Get the string from the user****************************************/

        printf( "\nEnter a string: " );
        gets( buff );

        printf( "\nDigest for \"%s\":", buff );

        /*****Calculate the checksum using Calculate******************************/

        printf( "\nCalculated using Calculate:           " );

        checksum = ( *pCalculate )( buff, strlen( buff ) );

        ( *pConvertToHex32 )( checksumhex, checksum, 0 );

        printf( "%s", checksumhex );

        /*****Initialize the context before calling Update, Final, or FinalHex****/

        ( *pInit )( &crcvar );

        /*****Calculate the checksum using Update and Final***********************/

        printf( "\nCalculated using Update and Final:    " );

        ( *pUpdate )( &crcvar, buff, strlen( buff ) );
        checksum = ( *pFinal )( &crcvar ); /* Final reinitializes the crcvar for the next use */

        ( *pConvertToHex32 )( checksumhex, checksum, 1 );

        printf( "%s", checksumhex );

        /*****Continue?***********************************************************/

        printf( "\nContinue (Y/N)?" );
        gets( buff );

    }while( *buff == 'y' || *buff == 'Y' );

    FreeLibrary( hModule );

    return 0;
}

 

 

FastCRC Library Overview   |   CRC32 API Overview   |   Useful Links   |   HashCalc

 

See Also    Function Indices in FastCRC.dll


 

 

Send Feedback to SlavaSoft Inc. Tell a friend about FastCRC Library