资源描述:
《vb源代码-crc32自校验(vb source code -crc32 self check)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、vb源代码-crc32自校验(VBsourcecode-crc32selfcheck)Classmodule(nameclsCRC)codeOptionExplicitPublicEnumCRCAlgorithmsCRC16CRC32EndEnumPrivatem_AlgorithmAsBooleanPrivatem_CRC16AsLongPrivatem_CRC16Asm()AsBytePrivatem_CRC16InitAsBooleanPrivatem_CRC16Table(0,To255)As
2、LongPrivatem_CRC32AsLongPrivatem_CRC32Asm()AsBytePrivatem_CRC32InitAsBooleanPrivatem_CRC32Table(0,To255)AsLongPrivate,Declare,Function,CallWindowProc,Lib,user32,Alias,CallWindowProcA,ByVal,As,Long,ByVal,hWnd,As,Long,ByVal,Msg,As,Long,ByVal,wParam,As,Lon
3、g,ByVal,lParam,As,Long,,lpPrevWndFunc,As,LongPublic,Function,AddBytes(ByteArray())AsByte)AsVariantDimByteSizeAsLongOn,Local,Error,GoTo,NoDataByteSize=UBound(ByteArray)-LBound(ByteArray)+1OnLocalErrorGoTo0SelectCasem_AlgorithmCaseCRC16Call,CallWindowProc
4、(VarPtr(m_CRC16Asm(0)),VarPtr(m_CRC16),VarPtr(ByteArray(LBound(ByteArray))),VarPtr(m_CRC16Table(0)),ByteSize)CaseCRC32Call,CallWindowProc(VarPtr(m_CRC32Asm(0)),VarPtr(m_CRC32),VarPtr(ByteArray(LBound(ByteArray))),VarPtr(m_CRC32Table(0)),ByteSize)EndSele
5、ctNoData:AddBytes=ValueEndFunctionPublic,Function,AddString(Text,As,String)AsVariantAddString=AddBytes(StrConv(Text,vbFromUnicode))EndFunctionPublic,Property,Let,Algorithm(New_Value,As,CRCAlgorithms)M_Algorithm=New_ValueSelectCasem_AlgorithmCaseCRC16If(
6、Not,m_CRC16Init),Then,Call,InitializeCRC16CaseCRC32If(Not,m_CRC32Init),Then,Call,InitializeCRC32EndSelectCallClearEndPropertyPublic,Property,Get,Algorithm(),As,CRCAlgorithmsAlgorithm=m_AlgorithmEndPropertyPublic,Function,CalculateBytes(ByteArray())AsByt
7、e)AsVariantCallClearCalculateBytes=AddBytes(ByteArray)EndFunctionPublic,Function,CalculateFile(Filename,As,String)AsVariantDimFilenrAsIntegerDimByteArray()AsByteIf(FileLen(Filename)=0)Then,Exit,FunctionFilenr=FreeFileOpen,Filename,For,Binary,As,#FilenrR
8、eDimByteArray(0,To,LOF(Filenr)-9)Get,#Filenr,ByteArray()Close#FilenrCalculateFile=CalculateBytes(ByteArray)EndFunctionPublic,Property,Get,Value(),As,VariantSelectCasem_AlgorithmCaseCRC16Value=(m_CRC16,And,65535)CaseCRC32Value=(No