本文使用Delphi和C++创建CRC32的COM文件(Dll)。
VB: V6.0
PB: V8.0
Delphi创建的文件,提供给VB6调用;C++创建的文件,提供给PB8调用。
一、VB部分
COM文件:FCN.dll
注册:regsvr32 x:\yyy\FCN.dll
1. 校验值文件
描述:保存FCN文件。
原型:procedure saveFCN(saveFile1,CheckFilePath:pchar);
参数:saveFile1: 保存文件的全路径(路径+文件名称)
CheckFilePath: 被校验文件的全路径
(1) 声明方法
Option Explicit
Private Declare Sub saveFCN Lib "FCN.dll" (ByVal saveFile1 As String, ByVal CheckFilePath As String)
(2) 调用方法
Call saveFCN(saveFile1, CheckFilePath1)
运行效果:
code: frmDemo.vb(VS2005)
Option Strict Off
Option Explicit On
Friend Class frmDemo
Inherits System.Windows.Forms.Form
Private Declare Sub saveFCN Lib "FCN.dll" (ByVal saveFile1 As String, ByVal CheckFilePath As String)
Private Sub cmdCall_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCall.Click
‘定义要保存的文件和检查的文件(具体路径和文件名称)
Dim saveFile1 As Object
Dim CheckFilePath1 As String
‘saveFile1 = "c:\s\datasb.fcn"
CheckFilePath1 = Text1.Text
‘UPGRADE_WARNING: Couldn‘t resolve default property of object saveFile1. Click for more: ‘ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"‘
saveFile1 = fcnPathTxt.Text
‘调用过程
‘UPGRADE_WARNING: Couldn‘t resolve default property of object saveFile1. Click for more: ‘ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"‘
Call saveFCN(saveFile1, CheckFilePath1)
Me.Text = "生成FCN文件-完成"
End Sub
End Class
2. 比较校验值
描述:计算文件的CRC32值。
原型:function calCRC32(filePath1:String):DWORD;
参数:filePath1: 要计算的文件(具体路径和文件名称)
描述:读取FCN文件的CRC32值。
原型:function readFCN(loadFile1:String):DWORD;
参数:loadFile1: 要读取的文件(具体路径和文件名称)
(1) 声明方法
Option Explicit
Private Declare Function calCRC32 Lib "FCN.dll" (ByVal filePath1 As String) As Long ‘calCRC32
Private Declare Function readFCN Lib "FCN.dll" (ByVal loadFile1 As String) As Long ‘readFCN
(2) 调用方法
‘计算
calCRC32(filePath1)
‘读值
readFCN(loadFile1)
运行效果:
code: rmDemCrc32.vb(VS2005)
Option Strict Off
Option Explicit On
Friend Class frmDemCrc32
Inherits System.Windows.Forms.Form
Private Declare Function calCRC32 Lib "FCN.dll" (ByVal filePath1 As String) As Integer
Private Declare Function readFCN Lib "FCN.dll" (ByVal loadFile1 As String) As Integer
Private Sub cmdCal_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdCal.Click
‘定义要计算的文件(具体路径和文件名称)
Dim filePath1 As String
filePath1 = filePathTxt.Text
‘调用函数
Label_cal.Text = CStr(calCRC32(filePath1))
End Sub
Private Sub cmdReadFCN_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReadFCN.Click
‘定义要读取的文件(具体路径和文件名称)
Dim loadFile1 As String
loadFile1 = fcnPathTxt.Text
‘调用函数
Label_read.Text = CStr(readFCN(loadFile1))
End Sub
End Class
二、PB部分
COM文件:FCV.dll
注册:regsvr32 x:\yyy\FCV.dll
下载PB8.0,请查看此论坛:http://www.sybasebbs.com/forum.php?mod=viewthread&tid=5568&fromuid=6