本篇讲程序2!
本程序主要有两个功能:计算CRC32数值和读取FCN文件的内容。
1.按钮事件cmdCal_Click()
Label_cal.Caption = calCRC32(filePath1)此接口有1个参数:
'定义要计算的文件(具体路径和文件名称) Dim filePath1 As String
外调函数声明:
'vb define Option Explicit Private Declare Function calCRC32 Lib "FCN.dll" (ByVal filePath1 As String) As Long
2.按钮事件cmdReadFCN_Click()
Label_read.Caption = readFCN(loadFile1)此接口有1个参数:
'定义要读取的文件(具体路径和文件名称) Dim loadFile1 As String
Private Declare Function readFCN Lib "FCN.dll" (ByVal loadFile1 As String) As Long
下面是完整的代码(frmDemCrc32.frm):
VERSION 5.00 Begin VB.Form frmDemCrc32 Caption = "CRC32演示" ClientHeight = 2790 ClientLeft = 60 ClientTop = 345 ClientWidth = 8895 BeginProperty Font Name = "宋体" Size = 9.75 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty LinkTopic = "Form1" ScaleHeight = 2790 ScaleWidth = 8895 StartUpPosition = 2 'CenterScreen Begin VB.TextBox fcnPathTxt Height = 495 Left = 600 TabIndex = 7 Text = "c:\s\datasb.fcn" Top = 1320 Width = 3735 End Begin VB.TextBox filePathTxt Height = 495 Left = 600 TabIndex = 6 Text = "c:\s\datasb.txt" Top = 360 Width = 3735 End Begin VB.CommandButton cmdReadFCN Caption = "读 FCN 文件" BeginProperty Font Name = "宋体" Size = 9 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 7440 TabIndex = 1 Top = 1320 Width = 1215 End Begin VB.CommandButton cmdCal Caption = "计算CRC32值" BeginProperty Font Name = "宋体" Size = 9 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 7440 TabIndex = 0 Top = 360 Width = 1215 End Begin VB.Label Label2 Caption = "读取值:" BeginProperty Font Name = "宋体" Size = 9 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4560 TabIndex = 5 Top = 1440 Width = 735 End Begin VB.Label Label1 Caption = "计算值:" BeginProperty Font Name = "宋体" Size = 9 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4560 TabIndex = 4 Top = 480 Width = 735 End Begin VB.Label Label_read ForeColor = &H80000001& Height = 495 Left = 5640 TabIndex = 3 Top = 1440 Width = 1605 End Begin VB.Label Label_cal ForeColor = &H80000001& Height = 495 Left = 5640 TabIndex = 2 Top = 480 Width = 1605 End End Attribute VB_Name = "frmDemCrc32" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Declare Function calCRC32 Lib "FCN.dll" (ByVal filePath1 As String) As Long Private Declare Function readFCN Lib "FCN.dll" (ByVal loadFile1 As String) As Long Private Sub cmdCal_Click() '定义要计算的文件(具体路径和文件名称) Dim filePath1 As String filePath1 = filePathTxt.Text '调用函数 Label_cal.Caption = calCRC32(filePath1) End Sub Private Sub cmdReadFCN_Click() '定义要读取的文件(具体路径和文件名称) Dim loadFile1 As String loadFile1 = fcnPathTxt.Text '调用函数 Label_read.Caption = readFCN(loadFile1) End Sub
附:
说明文件
文件接口
—CRC32动态库(FCN.DLL)
一、函数列表
参数名称 |
数据类型 |
返回值 |
备注 |
|
calCRC32 |
filePath1 |
String |
Long |
计算文件的CRC32值 |
readFCN |
loadFile1 |
String |
Long |
读取FCN文件的CRC32值 |
二、VB声明
1.计算文件的CRC32值
‘VB声明
PrivateDeclare Function calCRC32 Lib "FCN.dll" (ByVal filePath1 As String)As Long
2.读取FCN文件的CRC32值
‘VB声明
Private Declare Function readFCN Lib"FCN.dll" (ByVal loadFile1 As String) As Long
使用说明:(xiaobin)
请把MSVBVM60.DLL和FCN.dll与程序文件在一个目录里!