Xceed Encryption Library Documentation
Examples / Hashing a file (VC++ example)
In This Topic
    Hashing a file (VC++ example)
    In This Topic
    VC++ Copy Code

    // This code uses the #import directive.

    // Put the following line at the beginning of your module
    #import "XCEEDCRY.DLL" no_namespace named_guids 

    CoInitialize( NULL ); 

    try
    {
      IXceedHashingPtr piHash; 

      piHash.CreateInstance( CLSID_XceedHashing ); 
      piHash->License( _bstr_t( L"your license key ) ); 

      IXceedSHAHashingMethodPtr piSHA; 

      piSHA.CreateInstance( CLSID_XceedSHAHashingMethod );  
      piSHA->PutHashSize( 256 ); 

      piHash->HashingMethod = IXceedHashDataPtr( piSHA ); 

      BYTE* pcHashValue = NULL; 
      short nHashValueSize; 
      DWORD dwBytesRead;  

      piHash->ReadFile( "c:\\temp\\source.txt", 0, 0, efpHash, TRUE, &dwBytesRead );  

      piSHA->GetHashValue( &pcHashValue, &nHashValueSize );  

      //Do something with the HashValue...  

      MessageBox( NULL, "File hashed successfully to memory", "Hashing result", MB_OK );  

      CoTaskMemFree( pcHashValue ); 
    }
    catch( const _com_error& xErr )
    {
      char szMsg[50]; 
      wsprintf( szMsg, "Error %08x\n", xErr.Error() ); 
      MessageBox( NULL, szMsg, "Error", MB_OK ); 
    }
    catch( ... )
    {
      MessageBox( NULL, "Unknown error", "Error", MB_OK ); 

    CoUninitialize();