请教一个关于DLL制作和调用的问题
---------------------------------
    我要用VB6.0制作一个DLL文件,然后自己再调用它。遇到的问题是:
     1  DLL必须写在类模块里的函数,才能在程序中调用,否则会提示“找不到入口点函数”。我上网查了,据说可以使用.def文件来解决,但怎么加载使用这个def文件呢?
     2  当调用DLL中类模块里的所有函数时候,总提示参数类型不匹配。我可以保证的是调用的参数类型和DLL中声明的参数类型绝对一致(因为都是自己做的,也检查过了),那怎么才能解决这个问题呢?
     3  怎么样才能下传一个数组呢,按值传送和按地址传送?
     小生头次发帖,请大家多多关照。因为本人是做工业控制系统的,硬件熟悉,软件不太了解,如有愚笨之问,敬请谅解,给以指点,谢谢!

解决方案 »

  1.   

    先说第一个问题,不知你是如何调用这个函数,如果是用Declare是不行的,因为vb作的dll是不能输出函数的,想要作到这一点也可以但有点麻烦,网上有很多这方面的文章。
      

  2.   

    以下代码必须写在类模块里,然后作成DLL,调用程序才能看到函数;反之,写在MODUL里是看不到的,然后就是即使写在类模块里,调用时候遇到问题22  当调用DLL中类模块里的所有函数时候,总提示参数类型不匹配。我可以保证的是调用的参数类型和DLL中声明的参数类型绝对一致(因为都是自己做的,也检查过了),那怎么才能解决这个问题呢? 
    ------------------------------------------------------------------------------------
    Option Explicit
    '====================================================================
    '名称:VectorSum()
    '功能:向量加法
    '输入:V1A,V1P,V2A,V2P
    '输出:VA,VP
    '返回:两个向量的和
    '====================================================================
    Public Function VectorSum(V1A As Double, V1P As Double, V2A As Double, V2P As Double, VA As Double, VP As Double) As Boolean
    Dim dbReal, dbImaginary As Double
    Dim dbQuotient As Double
    dbReal = V1A * Cos(V1P) + V2A * Cos(V2P)
    dbImaginary = V1A * Sin(V1P) + V2A * Sin(V2P)
    VA = Sqr(dbReal ^ 2 + dbImaginary ^ 2)
    If dbReal <> 0 Then
       dbQuotient = dbImaginary / dbReal
       If dbReal > 0 Then
          If dbImaginary > 0 Then
          VP = Atn(dbQuotient)
          Exit Function
          Else
          VP = Atn(dbQuotient) + 2 * 3.1415926
          Exit Function
          End If
       Else
          VP = Atn(dbQuotient) + 3.1415926
          Exit Function
       End If
    Else
       If dbImaginary < 0 Then
          VP = 3.1415926 * 3 / 2
          Exit Function
       Else
          VP = 3.1415926 / 2
          Exit Function
       End If
    End IfEnd Function
    '======================================================================
    '名称:VectorSubtract()
    '功能:向量减法
    '输入:V1A,V1P,V2A,V2P
    '输出:VA,VP
    '返回:两个向量的差
    '======================================================================
    Public Function VectorSub(V1A As Double, V1P As Double, V2A As Double, V2P As Double, VA As Double, VP As Double) As Boolean
    Dim dbReal, dbImaginary As Double
    Dim dbQuotient As Double
    dbReal = V1A * Cos(V1P) - V2A * Cos(V2P)
    dbImaginary = V1A * Sin(V1P) - V2A * Sin(V2P)
    VA = Sqr(dbReal ^ 2 + dbImaginary ^ 2)
    If dbReal <> 0 Then
       dbQuotient = dbImaginary / dbReal
       If dbReal > 0 Then
          If dbImaginary > 0 Then
          VP = Atn(dbQuotient)
          Exit Function
          Else
          VP = Atn(dbQuotient) + 2 * 3.1415926
          Exit Function
          End If
       Else
          VP = Atn(dbQuotient) + 3.1415926
          Exit Function
       End If
    Else
       If dbImaginary < 0 Then
          VP = 3.1415926 * 3 / 2
          Exit Function
       Else
          VP = 3.1415926 / 2
          Exit Function
       End If
    End If
    End Function
    '======================================================================
    '名称:VectorMul()
    '功能:向量乘法
    '输入:V1A,V1P,V2A,V2P
    '输出:VA,VP
    '返回:两个向量的乘积
    '======================================================================
    Public Function VectorMul(V1A As Double, V1P As Double, V2A As Double, V2P As Double, VA As Double, VP As Double) As Boolean
    Dim a, P As Double
    VA = V1A * V2A
    P = V1P + V2P
    If P < 0 Then
       VP = P + 2 * 3.1415926
    ElseIf P > 2 * 3.1415926 Then
       VP = P - 2 * 3.1415926
    Else
       VP = P
    End IfEnd Function
    '======================================================================
    '名称:VectorDiv()
    '功能:向量除法
    '输入:V1A,V1P,V2A,V2P
    '输出:VA,VP
    '返回:两个向量的乘积
    '======================================================================
    Public Function VectorDiv(V1A As Double, V1P As Double, V2A As Double, V2P As Double, VA As Double, VP As Double) As Boolean
    Dim a, P As Double
    VA = V1A / V2A
    P = V1P - V2P
    If P < 0 Then
       VP = P + 2 * 3.1415926
    ElseIf P > 2 * 3.1415926 Then
       VP = P - 2 * 3.1415926
    Else
       VP = P
    End IfEnd Function
    '======================================================================
    '名称:PluralityToVector()
    '功能:复数转换矢量函数
    '输入:Re,Im
    '输出:VA,VP
    '返回:
    '======================================================================
    Public Function PluralityToVector(Re As Double, Im As Double, VA As Double, VP As Double) As Boolean
    Dim dbQuotient As Double
    VA = Sqr(Re ^ 2 + Im ^ 2)
    If Re <> 0 Then
       dbQuotient = Im / Re
       If Re > 0 Then
          If Im > 0 Then
          VP = Atn(dbQuotient)
          Exit Function
          Else
          VP = Atn(dbQuotient) + 2 * 3.1415926
          Exit Function
          End If
       Else
          VP = Atn(dbQuotient) + 3.1415926
          Exit Function
       End If
    Else
       If Im < 0 Then
          VP = 3.1415926 * 3 / 2
          Exit Function
       Else
          VP = 3.1415926 / 2
          Exit Function
       End If
    End If
    End Function
      

  3.   

    就没有办法调用啊,可否发个例子程序呢?[email protected]