首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

activeX DLL 的编译有关问题

2012-02-20 
activeX DLL 的编译问题问题描述:我在一个activeX dll中定义了一个类,将这个类作为其他各个dll与客户程序

activeX DLL 的编译问题
问题描述:
我在一个activeX dll中定义了一个类,将这个类作为其他各个dll与客户程序标志变量的公共载体,全局变量
在类中定义了一个timer 类型的变量g_timer2,以及一个control类型的变量g_MSCOMM,它作为一个对客户程序mscomm控件的引用,在其他dll中以及客户程序中都对该类在主程序中的对象进行了引用.在调试过程中,没有出现问题.
现在对该类进行编译,第一次在编译时选择no compatibility选项,生成gf.dll,二次编译选择binary compatibility选项,这时弹出'g_MSCOMM' in the 'Globalflags'class module has arguments and/or a return type that is incompatible with a similar declaration in the version compatible component.

Original definition:
 Public g_MSCOMM As Object

Current definition:
 Public g_MSCOMM As Control

Original definition:
 Property Set g_MSCOMM(ByVal RHS As Object)

Current definition:
 Public g_MSCOMM As Control

然后有两个选项 break compatibility 和 preserve compatibility

g_timer2也会出现同样的提示

我不明白究竟是哪里出了问题,这个向后兼容性究竟应该注意什么?我前后两次程序并没改动什么,g_MSCOMM,g_timer2的定义有问题吗?

VB code
 
Option Explicit
Public Offline As Boolean
Public SendingMsg As Boolean
Public SendAll As Boolean
Public langflag As Integer
Public FinishULData As Boolean
Public Iniflag As Boolean
Public FinishFlag As Boolean
Public PressStop As Boolean

Public Almshow As Boolean
Public SendFile As Boolean
Public AllowMoni As Boolean
Public FinishMoni As Boolean
Public SendPara As Boolean
Public Addr As Integer
Public addrStr1 As String
Public addrRecieve As String
Public ParaTabShow As Boolean

Public TestStyle As Integer
Public SparaExist As Boolean
Public reqTest As Boolean
Public DatAddr03 As String

Public coderight As Boolean
Public coderight1 As Boolean
Public ResumeFlag As Boolean
Public fftFlag As Boolean

Public message As String
Public AdjFlag As Integer
Public ServoType As String
Public TimerCount As Integer

[color=#FF0000]Public g_MSCOMM As Control
Public g_Timer2 As Timer[/color]

Public MDIhwnd As Long
Public SpecialShow As Boolean
Public PhaseShow As Boolean
Public OperationShow As Boolean
Public LoadingShow As Boolean
Public JOGShow As Boolean
Public InertiaShow As Boolean
Public HandShow As Boolean
Public DMShow As Boolean
Public IMShow As Boolean
Public ScopeShow As Boolean

Public fftCmdShow As Boolean
Public fftGraphicShow As Boolean
Public testCmdShow As Boolean
Public testGraphicShow As Boolean
Public testParaShow As Boolean

Public Cn As ADODB.Connection

Public Function ProcessContinue(ByVal hwnd As Long) As Boolean
  If Not FinishULData Then
      If Not PressStop Then
        ProcessContinue = False
        MessageBoxEx hwnd, "UpLoad Plot Data", , MB_OK Or MB_ICONINFORMATION, LANG_ENGLISH
        Exit Function
      End If
  End If
 
  If SendPara Then
      ProcessContinue = False
      MessageBoxEx hwnd, "SendPara", ,MB_OK Or MB_ICONINFORMATION, LANG_ENGLISH
      Exit Function
  End If
 
  If fftFlag Then
      ProcessContinue = False
      MessageBoxEx hwnd, "fftFlag", , MB_OK Or MB_ICONINFORMATION, LANG_ENGLISH
      Exit Function
  End If
 
 
  ProcessContinue = True
 
End Function

Public Sub SendingMessage(ByVal msg As String)

  Dim Out1() As Byte 
  Dim Lrc As Long
  Dim a As Integer
  Dim L As Integer
 


  SendingMsg = True
 
  msg = addrStr1 & msg
  L = Len(msg)
  Dim i As Integer
  Lrc = 0
 
  For i = 0 To L / 2 - 1
    a = Val("&H" & Mid(msg, 2 * i + 1, 2))
    Lrc = a + Lrc
  Next
 
  Lrc = Lrc Mod 256
  Lrc = 256 - Lrc
 
  If Lrc = 256 Then
    Lrc = 0
  End If
 
  ReDim Out1(L + 4) As Byte
  For i = 1 To L
    Out1(i) = Asc(Mid(msg, i, 1))
  Next i
 
  If Lrc < 16 Then
    Out1(L + 1) = Asc(Mid("0" & Hex(Lrc), 1, 1))
    Out1(L + 2) = Asc(Mid("0" & Hex(Lrc), 2, 1))
  Else
    Out1(L + 1) = Asc(Mid(Hex(Lrc), 1, 1))
    Out1(L + 2) = Asc(Mid(Hex(Lrc), 2, 1))
  End If
 
  Out1(0) = Asc(":")
  Out1(L + 3) = &HD
  Out1(L + 4) = &HA
 
  If g_MSCOMM.PortOpen = True Then
      g_MSCOMM.OutBufferCount = 0
      g_MSCOMM.Output = Out1  '
  End If
 
End Sub



[解决办法]
编译时选择二进制兼容模式。还有,你那些这是定义,如果不是供外部引用,就改成private。
[解决办法]
VB.Control 其实是 VB 内部的一个特殊类,它自动对控件进行封装让它们具有一定的共性。
比如用 MSComm 控件调用下面的函数可以正常工作,但是在其它编程环境中就不会有 .Parent 属性。
VB code
Private Sub f(ByVal c As Control)    Debug.Print c.Parent.Name    Debug.Print c.CommPortEnd Sub
[解决办法]
在 COM 标准中没有公共变量,一个属性通过 {get_XXX, set_XXX, let_XXX} 等方法表示。
VB 自动将公共变量翻译为属性,所以接口中就有 Property Set g_MSCOMM(...)。

具体细节可用 Visual Studio 的工具 OLE View 打开 dll 查看。

热点排行