COM调用 – VB、PB

本文使用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: 要读取的文件(具体路径和文件名称)

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

‘计算

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

1. PB工程图解

(1) 建立工作区

File->New

保存工作区名称

(2) 建立目标类型

点击工作区名称,右键New;

然后,选择“Application”。

输入应用程序名称;然后,点击下面两个任意输入框,向导会自动填充下面的两个输入框。

(3) 建立窗口

点击应用程序名称,右键New;

然后,选择“Window”。

初始状态的窗口

点击“layout”选项卡,即可设计窗口控件。

拖拽windows控件

添加按钮

点击工具栏中的按钮图标;然后,点击窗口即完成。

点击工具栏中的保存图标;即完成窗口的设计工作。

2. 添加代码

(1) 按钮事件

双击放置的按钮,在里面添加代码。


string      strCrc32,strFile
int   		intValue   
oleobject   objOle   
objOle      = create OLEObject   
intValue    = objOle.connecttonewobject("FCV.UCRC32.1")

strFile     = "d:\QQIntl2.11.exe"

if fileexists(strFile) then
	strCrc32    = string(objOle.CalCRC32(strFile))
   messagebox("test",strCrc32)
else
	messagebox("test",strFile + " not found")
end if


(2) 主窗口事件

应用程序启动主窗口。

点击带红色齿轮的图标,右键Edit,增加应用程序open事件;

3. 打包程序

(1) 建立工程

选择“Application”

填写如下部署程序信息,并保存。

(2) 编译并部署

点击应用程序名称,右键Full Build;然后,再点击Deploy。

应用程序执行效果:

演示程序下载:百度网盘

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...