VB 用汇编进行快速CRC较验

因为利用了汇编代码,速度特别快,有空可以测试测试.
新建一个EXE工程,加入两个TEXTBOX控件,默认名称,一个BUTTON控件即可.

Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" ( ByVal lpPrevWndFunc As Long , _
ByVal hwnd As Long , _
ByVal Msg As Long , _
ByVal wParam As Long , _
ByVal lParam As Long ) As Long


Private Function
AsmCrc(bytInput() As Byte , ByVal Init As Long ) As Long
Dim
Asm( 5 ) As Long
Asm( 0 ) = &H5B5A5958
Asm( 1 ) = &HC033505E
Asm( 2 ) = &H3018A36
Asm( 3 ) = &H41CED1F0
Asm( 4 ) = &HF47ECA3B
Asm( 5 ) = &HC3338936
CallWindowProc VarPtr(Asm( 0 )), _
VarPtr(bytInput(LBound(bytInput))), _
VarPtr(bytInput(UBound(bytInput))), _
VarPtr(AsmCrc), _
Init
End Function

Private Sub
Command1_Click()
Dim myBAry() As Byte
Dim
myL As Long

myBAry = StrConv(Text1.Text, vbFromUnicode)

myL = AsmCrc(myBAry, Len(Text1.Text))
Text2.Text =
"字符串“" & Text1.Text & "”的CRC校验:" & myL
End Sub

 

你可能感兴趣的:(vb)