码迷,mamicode.com
首页 > 编程语言 > 详细

COM调用–Delphi、PB、C++、VB

时间:2016-01-09 06:11:51      阅读:343      评论:0      收藏:0      [点我收藏+]

标签:

    本文使用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

COM调用–Delphi、PB、C++、VB

标签:

原文地址:http://www.cnblogs.com/xiaobin-hlj80/p/5115336.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!